Exemple #1
0
        public static void PlayerLogin(LoginClient client, uint id)
        {
            if (client.Account == null)
            {
                client.Close("Tried to login with a character without an account.");
                return;
            }
            DataObject[] chars = DataServer.Database.SelectObjects(typeof(DBCharacter), "Character_ID = '" + id + "'");
            if (chars.Length == 0)
            {
                client.Close("Failed to find character in database?");
                return;
            }
            DBCharacter c = (DBCharacter)chars[0];

            if (c.AccountID != client.Account.ObjectId)
            {
                client.Close("Tried to login another account's character.");
                return;
            }
            client.Character = c;
            if (c.WorldMapID == 0)
            {
                client.Close(c.Name + " is missing world map id.");
                return;
            }
            client.WorldConnection = (WorldConnection)m_worldMapServer[c.WorldMapID];
            if (client.WorldConnection == null)
            {
                client.Close("Missing worldserver for world map id " + c.WorldMapID);
                return;
            }
            m_loginCharacters[id] = client;
            client.OnEnterWorld();
        }
        public static void PlayerLogin(LoginClient client, uint id)
        {
            if (client.Account == null)
            {
                client.Close("Tried to login with a character without an account.");
                return;
            }
            DataObject[] chars = DataServer.Database.SelectObjects(typeof(DBCharacter), "Character_ID = '" + id + "'");
            if (chars.Length == 0)
            {
                client.Close("Failed to find character in database?");
                return;
            }
            DBCharacter c = (DBCharacter)chars[0];

            if (c.AccountID != client.Account.ObjectId)
            {
                client.Close("Tried to login another account's character.");
                return;
            }
            client.Character = c;
            if (client.Character.GuildID != 0)
            {
                DBGuild guild = (DBGuild)DataServer.Database.FindObjectByKey((typeof(DBGuild)), client.Character.GuildID);
                if (guild != null)
                {
                    client.Character.Guild     = guild;
                    client.Character.GuildName = guild.Name;
                }
                else
                {
                    client.Character.GuildID   = 0;
                    client.Character.GuildRank = 0;
                    client.Character.GuildName = " ";
                }
            }
            string[] RemoteIP = client.RemoteEndPoint.ToString().Split(':');
            client.Account.LastIP = RemoteIP[0];
            if (c.WorldMapID == 0)
            {
                client.Close(c.Name + " is missing world map id.");
                return;
            }
            client.WorldConnection = (WorldConnection)m_worldMapServer[c.WorldMapID];
            if (client.WorldConnection == null)
            {
                client.Close("Missing worldserver for world map id " + c.WorldMapID);
                return;
            }
            m_loginCharacters[id] = client;
            FriendIsOnline(client);
            client.OnEnterWorld();
//			client.WorldConnection.OnEnterWorld(client.Character, client.Account.AccessLvl);
        }
        static bool OnCreatureQuery(LoginClient client, CMSG msgID, BinReader data)
        {
            uint       id       = data.ReadUInt32();
            DBCreature creature = (DBCreature)DataServer.Database.FindObjectByKey(typeof(DBCreature), id);

            if (creature == null)
            {
                client.Close("OnCreatureQuery(): id didn't exists.");
                return(true);
            }
            BinWriter w = LoginClient.NewPacket(SMSG.CREATURE_QUERY_RESPONSE);

            w.Write(creature.ObjectId);
            w.Write(creature.Name);
            w.Write(creature.Name1);
            w.Write(creature.Name2);
            w.Write(creature.Name3);
            w.Write(creature.Title);
            w.Write(creature.Flags);
            w.Write(creature.CreatureType);
            w.Write(creature.CreatureFamily);
            w.Write(0);             // unknown
            client.Send(w);
            return(true);
        }
        static bool OnItemQuerySingle(LoginClient client, CMSG msgID, BinReader data)
        {
            uint           id       = data.ReadUInt32();
            DBItemTemplate template = (DBItemTemplate)DataServer.Database.FindObjectByKey(typeof(DBItemTemplate), id);

            if (template == null)
            {
                client.Close("Client requested an item template that didn't exists.");
                return(true);
            }
            BinWriter w = LoginClient.NewPacket(SMSG.ITEM_QUERY_SINGLE_RESPONSE);

            w.Write(id);
            foreach (SerializeValue value in itemTemplateValues)
            {
                value.Serialize(template, w);
            }
            client.Send(w);
            return(true);
        }
        static bool OnNameQuery(LoginClient client, CMSG msgID, BinReader data)
        {
            uint        id    = data.ReadUInt32();
            LoginClient other = LoginServer.GetLoginClientByCharacterID(id);

            if (other == null)
            {
                client.Close("Tried to query a char that wasn't online.");
                return(true);
            }
            BinWriter pkg = LoginClient.NewPacket(SMSG.NAME_QUERY_RESPONSE);

            pkg.Write(other.Character.ObjectId);
            pkg.Write(0);             // high id
            pkg.Write(other.Character.Name);
            pkg.Write((int)other.Character.Race);
            pkg.Write((int)other.Character.Gender);
            pkg.Write((int)other.Character.Class);
            client.Send(pkg);
            return(true);
        }
        internal static void ChangeMap(LoginClient client)
        {
            client.WorldConnection = (WorldConnection)m_worldMapServer[client.Character.WorldMapID];
            if (client.WorldConnection == null)
            {
                client.Close("(ChangeMap) Missing worldserver for world map id " + client.Character.WorldMapID);
                return;
            }

            DBWorldMap map = (DBWorldMap)DataServer.Database.FindObjectByKey(typeof(DBWorldMap), client.Character.WorldMapID);

            client.Character.Continent = (uint)map.Continent;

            BinWriter pkg = LoginClient.NewPacket(SMSG.NEW_WORLD);

            pkg.Write((byte)client.Character.Continent);
            pkg.WriteVector(client.Character.Position);
            pkg.Write(client.Character.Facing);
            client.Send(pkg);
            FriendIsOnline(client);
            client.WorldConnection.OnEnterWorld(client.Character, client.Account.AccessLvl);
        }
        static void OnPlayerLeaveWorld(WorldConnection connection, WORLDMSG msgID, BinReader data)
        {
            LoginClient client = LoginServer.GetLoginClientByCharacterID(data.ReadUInt32());

            if (client == null)
            {
                return;
            }
            if (client.IsLoggingOut)
            {
                LoginServer.RemoveCharacter(client);
                BinWriter pkg = LoginClient.NewPacket(SMSG.LOGOUT_COMPLETE);
                client.Send(pkg);
                client.IsLoggingOut    = false;
                client.WorldConnection = null;
            }
            else if (client.IsChangingMap)
            {
            }
            else
            {
                client.Close("Kicked from worldserver.");
            }
        }