static void OnChangeMap(WorldConnection connection, WORLDMSG msgID, BinReader data)
        {
            uint        id     = data.ReadUInt32();
            LoginClient client = LoginServer.GetLoginClientByCharacterID(id);

            client.IsChangingMap = true;
        }
Exemple #2
0
        public override void OnClientLoopStop()
        {
            IEnumerator e = new ArrayList(m_worldServers).GetEnumerator();

            while (e.MoveNext())
            {
                WorldConnection connection = (WorldConnection)e.Current;
                if (!connection.processWorldServerData())
                {
                    if (m_shutdown == false)
                    {
                        Console.WriteLine("Lost connection to world server " + connection.ToString());
                        LoginServer.Shutdown();
                    }
                    else
                    {
                        m_worldServers.Remove(connection);
                    }
                }
            }

            if (m_shutdown && m_worldServers.Count == 0)
            {
                base.Stop();
            }

            Thread.Sleep(5);
        }
        public static void FriendIsOnline(LoginClient client)
        {
            LoginClient FriendOnline = null;
            BinWriter   flist        = null;

            if (client.Character.OnFriends != null)
            {
                foreach (DBFriendList Friend in client.Character.OnFriends)
                {
                    FriendOnline = LoginServer.GetLoginClientByCharacterID(Friend.Owner_ID);
                    if (FriendOnline != null)
                    {
                        flist = LoginClient.NewPacket(SMSG.FRIEND_STATUS);
                        //						Chat.System(FriendOnline, client.Character.Name+" is Online");
                        flist.Write((char)0x02);
                        flist.Write((ulong)client.Character.ObjectId);

                        flist.Write((int)client.Character.Zone);
                        flist.Write((int)client.Character.Level);
                        flist.Write((int)client.Character.Class);
                        FriendOnline.Send(flist);
                    }
                    FriendOnline = null;
                    flist        = null;
                }
            }
        }
 internal static void RemoveCharacter(LoginClient client)
 {
     if (client.Character != null)
     {
         m_loginCharacters.Remove(client.Character.ObjectId);
         if (client.Character.OnFriends != null)
         {
             BinWriter   flist        = null;
             LoginClient FriendOnline = null;
             foreach (DBFriendList Friend in client.Character.OnFriends)
             {
                 flist        = LoginClient.NewPacket(SMSG.FRIEND_STATUS);
                 FriendOnline = LoginServer.GetLoginClientByCharacterID(Friend.Owner_ID);
                 if (FriendOnline != null)
                 {
                     //							Chat.System(FriendOnline, client.Character.Name+" has Gone Offline");
                     flist.Write((char)0x03);
                     flist.Write((ulong)client.Character.ObjectId);
                     FriendOnline.Send(flist);
                 }
                 FriendOnline = null;
                 flist        = null;
             }
         }
         client.Character = null;
     }
 }
 static bool OnPlayerLogoutExecute(LoginClient client, CMSG msgID, BinReader data)
 {
     LoginServer.LeaveWorld(client);
     if (logOutEvent != null)
     {
         EventManager.RemoveEvent(logOutEvent);
         logOutEvent = null;
     }
     return(true);
 }
Exemple #6
0
        public static void System(string msg)
        {
            BinWriter pkg = LoginClient.NewPacket(SMSG.MESSAGECHAT);

            pkg.Write((byte)CHATMESSAGETYPE.SYSTEM);
            pkg.Write((int)0);
            pkg.Write((ulong)0);
            pkg.Write(msg);
            pkg.Write((byte)0);
            LoginServer.BroadcastPacket(pkg);
        }
        static bool OnPlayerLogout(LoginClient client, CMSG msgID, BinReader data)
        {
            client.IsLoggingOut = true;
            LoginServer.LeaveWorld(client);
            return(true);

            /*logOutEvent= new LogOut(client);
             * EventManager.AddEvent(logOutEvent);
             * BinWriter pkg = LoginClient.NewPacket(SMSG.LOGOUT_RESPONSE);
             * pkg.Write((byte)12);
             * client.Send(pkg);
             * return true;*/
        }
Exemple #8
0
 public override void Close(string reason)
 {
     if (m_account != null)
     {
         Account = null;
     }
     if (m_character != null)
     {
         LoginServer.LeaveWorld(this);
         LoginServer.RemoveCharacter(this);
     }
     Console.WriteLine(this + " closed: " + reason);
     base.Close(reason);
 }
Exemple #9
0
        static bool OnMessageChat(LoginClient client, CMSG msgID, BinReader data)
        {
            CHATMESSAGETYPE type = (CHATMESSAGETYPE)data.ReadInt32();

            /*int language =*/ data.ReadInt32();
            string target = string.Empty;

            if (type == CHATMESSAGETYPE.WHISPER)
            {
                target = data.ReadString(0x100);
            }
            string msg = data.ReadString(0x100);

            if (msg.StartsWith("!") || msg.StartsWith("%"))
            {
                return(OnChatCommand(client, msg.Substring(1)));
            }
            switch (type)
            {
            case CHATMESSAGETYPE.SAY:
            case CHATMESSAGETYPE.YELL:
            case CHATMESSAGETYPE.EMOTE:
                return(false);                        // let worldserver handle it

            case CHATMESSAGETYPE.WHISPER:
            {
                DataObject[] objs = DataServer.Database.SelectObjects(typeof(DBCharacter), "Name = '" + target + "'");
                if (objs.Length == 0)
                {
                    Chat.System(client, "No such player.");
                    return(true);
                }
                LoginClient targetClient = LoginServer.GetLoginClientByCharacterID(objs[0].ObjectId);
                if (targetClient == null || targetClient.Character == null)
                {
                    Chat.System(client, "That player is not online.");
                    return(true);
                }
                Chat.Whisper(client, targetClient, msg);
                break;
            }

            default:
                Chat.System(client, "Received " + type + ": " + msg);
                break;
            }
            return(true);
        }
Exemple #10
0
        public override void OnClientLoopStop()
        {
            try
            {
                IEnumerator e = new ArrayList(m_worldServers).GetEnumerator();
                while (e.MoveNext())
                {
                    WorldConnection connection = (WorldConnection)e.Current;
                    if (!connection.processWorldServerData())
                    {
                        if (m_shutdown == false)
                        {
                            Console.WriteLine("Lost connection to world server " + connection.ToString());
                            LoginServer.Shutdown();
                        }
                        else
                        {
                            m_worldServers.Remove(connection);
                        }
                        DebugLogger.Log("Lost connection to world server " + connection.ToString() + " -- Server will be restarted!");
                        LoginServer.RestartServer = true;
                    }
                }

                if (m_shutdown && m_worldServers.Count == 0)
                {
                    base.Stop();
                }

                Thread.Sleep(5);
            }
            catch (Exception exp)
            {
                if (exp.GetType() != typeof(ThreadAbortException))
                {
                    DebugLogger.Log("Will restart server!", exp);
                }

                LoginServer.RestartServer = 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 bool processWorldServerData()
         * {
         *      if(m_client.PendingSendData)
         *              m_client.SendWork();
         *      if(m_client.Connected == false)
         *              return false;
         *      byte[] data;
         *      while((data = m_client.GetNextPacketData()) != null)
         *              OnWorldServerData(data);
         *      return m_client.Connected;
         * }*/

        private void OnWorldServerData(ClientBase c, byte[] data)
        {
            BinReader read = new BinReader(data);

            read.BaseStream.Position += 4;             // skip len
            WORLDMSG msgID = (WORLDMSG)read.ReadInt32();

            if (msgID == WORLDMSG.SERVER_MESSAGE)
            {
                SMSG smsg = (SMSG)read.ReadInt32();
                Console.WriteLine("WorldServer sent: " + smsg);
                int       len = read.ReadInt32();
                BinWriter pkg = LoginClient.NewPacket(smsg);
                if (len > 0)
                {
                    pkg.Write(read.ReadBytes(len));
                }
                while (read.BaseStream.Position < read.BaseStream.Length)
                {
                    uint        plrID  = read.ReadUInt32();
                    LoginClient client = LoginServer.GetLoginClientByCharacterID(plrID);
                    if (client == null)
                    {
                        Console.WriteLine("client missing for plrID " + plrID + " while sending " + smsg.ToString());
                    }
                    else
                    {
                        client.Send(pkg);
                    }
                }
            }
            else if (msgID == WORLDMSG.SCRIPT_MESSAGE)
            {
                LoginServer.Scripts.OnScriptMessage(read.ReadInt32(), read);
            }
            else
            {
                LoginPacketManager.HandlePacket(this, msgID, read);
            }
        }
        static bool OnNameQuery(LoginClient client, CMSG msgID, BinReader data)
        {
            ulong       uid   = data.ReadUInt32();
            BinWriter   pkg   = LoginClient.NewPacket(SMSG.NAME_QUERY_RESPONSE);
            uint        id    = (uint)uid;
            LoginClient other = LoginServer.GetLoginClientByCharacterID(id);

            if (other == null)
            {
                DataObject[] objTemp = DataServer.Database.SelectObjects(typeof(DBCharacter), "Character_ID = '" + id + "'");
                if (objTemp.Length == 0)
                {
                    Console.WriteLine("Character not found");
                }
                else
                {
                    DBCharacter objCharacter = (DBCharacter)objTemp[0];
                    pkg.Write((ulong)objCharacter.ObjectId);
//					pkg.Write((uint)0); // high id
                    pkg.Write(objCharacter.Name);
                    pkg.Write((int)objCharacter.Race);
                    pkg.Write((int)objCharacter.Gender);
                    pkg.Write((int)objCharacter.Class);
                    client.Send(pkg);
                }
                return(true);
            }
            pkg.Write((ulong)other.Character.ObjectId);
//			pkg.Write((uint)0); // high id
//			pkg.Write(0);
            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);
        }
        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.");
            }
        }
 public override void FireEvent()
 {
     LoginServer.LeaveWorld(client);
 }
        static bool OnMessageChat(LoginClient client, CMSG msgID, BinReader data)
        {
            CHATMESSAGETYPE type = (CHATMESSAGETYPE)data.ReadInt32();

            /*int language =*/ data.ReadInt32();
            string target = string.Empty;

            if (type == CHATMESSAGETYPE.WHISPER)
            {
                target = data.ReadString(0x100);
            }
            string msg = data.ReadString(0x100);

            if (msg.StartsWith("!") || msg.StartsWith("%"))
            {
                return(OnChatCommand(client, msg.Substring(1)));
            }
            switch (type)
            {
            case CHATMESSAGETYPE.PARTY:
            case CHATMESSAGETYPE.CHANNEL:
            case CHATMESSAGETYPE.CHANNEL_JOIN:
            case CHATMESSAGETYPE.CHANNEL_LEAVE:
            case CHATMESSAGETYPE.CHANNEL_LIST:
            case CHATMESSAGETYPE.CHANNEL_NOTICE:
            case CHATMESSAGETYPE.CHANNEL_NOTICE_USER:
            case CHATMESSAGETYPE.SAY:
            case CHATMESSAGETYPE.YELL:
            case CHATMESSAGETYPE.EMOTE:
                return(false);                        // let worldserver handle it

            case CHATMESSAGETYPE.WHISPER:
            {
                DataObject[] objs = DataServer.Database.SelectObjects(typeof(DBCharacter), "Name = '" + target + "'");
                if (objs.Length == 0)
                {
                    Chat.System(client, "No such player.");
                    return(true);
                }
                LoginClient targetClient = LoginServer.GetLoginClientByCharacterID(objs[0].ObjectId);
                if (targetClient == null || targetClient.Character == null)
                {
                    Chat.System(client, "That player is not online.");
                    return(true);
                }
                Chat.Whisper(client, targetClient, msg);
                break;
            }

            case CHATMESSAGETYPE.GUILD:
            {
                DBGuild guild = client.Character.Guild;
                if (guild == null)
                {
                    return(true);
                }
                if ((guild.getRankFlags(client.Character.GuildRank) & (uint)GUILDFLAGS.SAY) == (uint)GUILDFLAGS.SAY)
                {
                    foreach (DBGuildMembers member in guild.Members)
                    {
                        if ((guild.getRankFlags(member.Rank) & (uint)GUILDFLAGS.LISTEN) == (uint)GUILDFLAGS.LISTEN)
                        {
                            LoginClient targetClient = LoginServer.GetLoginClientByCharacterID(member.MemberID);
                            if (targetClient == null || targetClient.Character == null)
                            {
                                continue;
                            }
                            else
                            {
                                Chat.GuildSay(client.Character.ObjectId, targetClient, msg, CHATMESSAGETYPE.GUILD);
                            }
                        }
                    }
                }
                else
                {
                    Chat.GuildSay(0, client, "You do not have permission", CHATMESSAGETYPE.GUILD);
                }

                break;
            }

            case CHATMESSAGETYPE.OFFICER:
            {
                DBGuild guild = client.Character.Guild;
                if (guild == null)
                {
                    return(true);
                }
                if ((guild.getRankFlags(client.Character.GuildRank) & (uint)GUILDFLAGS.OFFICER_SAY) == (uint)GUILDFLAGS.OFFICER_SAY)
                {
                    foreach (DBGuildMembers member in guild.Members)
                    {
                        if ((guild.getRankFlags(member.Rank) & (uint)GUILDFLAGS.OFFICER_LISTEN) == (uint)GUILDFLAGS.OFFICER_LISTEN)
                        {
                            LoginClient targetClient = LoginServer.GetLoginClientByCharacterID(member.MemberID);
                            if (targetClient == null || targetClient.Character == null)
                            {
                                continue;
                            }
                            else
                            {
                                Chat.GuildSay(client.Character.ObjectId, targetClient, msg, CHATMESSAGETYPE.OFFICER);
                            }
                        }
                    }
                }
                else
                {
                    Chat.GuildSay(0, client, "You do not have permission", CHATMESSAGETYPE.GUILD);
                }

                break;
            }

            default:
                Chat.System(client, "Received " + type + ": " + msg);
                break;
            }
            return(true);
        }
 static bool OnPlayerLogout(LoginClient client, CMSG msgID, BinReader data)
 {
     client.IsLoggingOut = true;
     LoginServer.LeaveWorld(client);
     return(true);
 }