<commit_before>/*
 * SelectCharacterCallback.h
 *
 *  Created on: Sep 5, 2009
 *      Author: theanswer
 */

#ifndef SELECTCHARACTERCALLBACK_H_
#define SELECTCHARACTERCALLBACK_H_

#include "../MessageCallback.h"

#include "server/zone/ZoneServer.h"
#include "server/zone/managers/player/PlayerManager.h"

#include "server/zone/objects/player/PlayerCreature.h"
#include "server/zone/objects/player/PlayerObject.h"

#include "server/chat/ChatManager.h"

class SelectCharacterCallback : public MessageCallback {
	uint64 characterID;
public:
	SelectCharacterCallback(ZoneClientSession* client, ZoneProcessServerImplementation* server) :
		MessageCallback(client, server) {

	}

	void parse(Message* message) {
		characterID = message->parseLong(6);
	}

	void run() {
		ZoneServer* zoneServer = server->getZoneServer();
		//ObjectManager* objectManager = zoneServer->getObjectManager();

		ManagedReference<SceneObject*> obj = zoneServer->getObject(characterID, true);

		if (obj != NULL && obj->isPlayerCreature()) {
			PlayerCreature* player = (PlayerCreature*) obj.get();

			Locker _locker(player);

			ManagedReference<ZoneClientSession*> oldClient = player->getClient();

			if (oldClient != NULL && client != oldClient) {

				_locker.release();

				oldClient->disconnect();

				return;
			}

			player->setClient(client);
			client->setPlayer(obj);

			Zone* zone = player->getZone();

			if (zone != NULL) {
				//reload

				player->reload(client);

			} else {
				int zoneID = player->getSavedZoneID();
				uint64 savedParentID = player->getSavedParentID();

				ManagedReference<SceneObject*> parent = zoneServer->getObject(savedParentID, true);

				if (parent != NULL) {
					try {
						parent->wlock(player);

						parent->addObject(player, -1);

						parent->unlock();
					} catch (...) {
						parent->unlock();
					}
				}

				zone = zoneServer->getZone(zoneID);

				player->insertToZone(zone);
			}

			player->setOnline();

			ChatManager* chatManager = zoneServer->getChatManager();
			chatManager->addPlayer(player);
			chatManager->loadMail(player);

			PlayerObject* ghost = player->getPlayerObject();
			ghost->notifyOnline();
<commit_msg>[fixed] player loading with wrong saved zone id<commit_after>/*
 * SelectCharacterCallback.h
 *
 *  Created on: Sep 5, 2009
 *      Author: theanswer
 */

#ifndef SELECTCHARACTERCALLBACK_H_
#define SELECTCHARACTERCALLBACK_H_

#include "../MessageCallback.h"

#include "server/zone/ZoneServer.h"
#include "server/zone/managers/player/PlayerManager.h"

#include "server/zone/objects/player/PlayerCreature.h"
#include "server/zone/objects/player/PlayerObject.h"

#include "server/chat/ChatManager.h"

class SelectCharacterCallback : public MessageCallback {
	uint64 characterID;
public:
	SelectCharacterCallback(ZoneClientSession* client, ZoneProcessServerImplementation* server) :
		MessageCallback(client, server) {

	}

	void parse(Message* message) {
		characterID = message->parseLong(6);
	}

	void run() {
		ZoneServer* zoneServer = server->getZoneServer();
		//ObjectManager* objectManager = zoneServer->getObjectManager();

		ManagedReference<SceneObject*> obj = zoneServer->getObject(characterID, true);

		if (obj != NULL && obj->isPlayerCreature()) {
			PlayerCreature* player = (PlayerCreature*) obj.get();

			Locker _locker(player);

			ManagedReference<ZoneClientSession*> oldClient = player->getClient();

			if (oldClient != NULL && client != oldClient) {

				_locker.release();

				oldClient->disconnect();

				return;
			}

			player->setClient(client);
			client->setPlayer(obj);

			Zone* zone = player->getZone();

			if (zone != NULL) {
				//reload

				player->reload(client);

			} else {
				int zoneID = player->getSavedZoneID();
				uint64 savedParentID = player->getSavedParentID();

				ManagedReference<SceneObject*> parent = zoneServer->getObject(savedParentID, true);

				if (parent != NULL) {
					try {
						parent->wlock(player);

						parent->addObject(player, -1);

						parent->unlock();
					} catch (...) {
						parent->unlock();
					}
				}

				try {
					zone = zoneServer->getZone(zoneID);
				} catch (...) {
					zone = NULL;
				}

				if (zone == NULL && parent != NULL)
					zone = parent->getRootParent()->getZone();

				if (zone == NULL)
					zone = zoneServer->getZone(0);

				player->insertToZone(zone);
			}

			player->setOnline();

			ChatManager* chatManager = zoneServer->getChatManager();
			chatManager->addPlayer(player);
			chatManager->loadMail(player);

			PlayerObject* ghost = player->getPlayerObject();
			ghost->notifyOnline();

{'fraction_non_alphanumeric': 0.1414207650273224, 'fraction_numerical': 0.005027322404371585, 'mean_word_length': 3.878464818763326, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5527081', 'n_tokens_mistral': 1683, 'n_tokens_neox': 1367, 'n_words': 263}