Beispiel #1
0
 public MapClient(uint session)
 {
     this.SessionID = session;
     this.state = SESSION_STATE.NOT_IDENTIFIED;
     this.lastHeartbeatRequest = 0;
     this.taskHeartbeat = new SagaMap.Tasks.SystemTasks.CheckHeartbeat(this);
 }
Beispiel #2
0
        public void SendToMap(Packets.Login.Get.SendToMap p)
        {
            string server = p.GetIPAddress() + ":" + p.GetPort().ToString();

            this.serverIP = server;
            MapSession map;

            this.state = SESSION_STATE.REDIRECTING;
            Dictionary <string, MapSession> maps = Gateway.Maps;

            if (maps.ContainsKey(server))
            {
                map = maps[server];
            }
            else
            {
                map = new MapSession(p.GetIPAddress(), p.GetPort(), this.SessionID);
                maps.Add(server, map);
            }
            this.MapSession = map;
            map.NewSession(this, p.GetCharID(), p.GetValidationKey());
            //this.MapSession = new MapSession(p.GetIPAddress(), p.GetPort(), p.GetCharID(), p.GetValidationKey(),this.SessionID,this);
            //this.MapSession.Connect();
            //this.LogingSession.netIO.Disconnect();
        }
Beispiel #3
0
 public override void OnDisconnect()
 {
     try
     {
         if (this.state == SESSION_STATE.LOGIN)
         {
             this.state = SESSION_STATE.DISCONNECTED;
             if (!this.onKick)
             {
                 Gateway.Login.Logout(this);
             }
         }
         if (this.state == SESSION_STATE.MAP)
         {
             this.state = SESSION_STATE.DISCONNECTED;
             Gateway.Login.Logout(this);
             if (!this.onKickMap)
             {
                 this.MapSession.Logout(this);
             }
         }
         this.state = SESSION_STATE.DISCONNECTED;
         GatewayClientManager.Instance.OnClientDisconnect(this);
     }
     catch (Exception ex)
     {
         Logger.ShowError(ex, null);
     }
 }
Beispiel #4
0
 public MapClient(uint session)
 {
     this.SessionID            = session;
     this.state                = SESSION_STATE.NOT_IDENTIFIED;
     this.lastHeartbeatRequest = 0;
     this.taskHeartbeat        = new SagaMap.Tasks.SystemTasks.CheckHeartbeat(this);
 }
Beispiel #5
0
        public void Connect()
        {
            bool Connected = false;
            int  times     = 5;

            do
            {
                if (times < 0)
                {
                    Logger.ShowError("Cannot connect to the Mapserver,please check the configuration!", null);
                    Gateway.ShutingDown(null, null);
                    //Gateway.Init();
                    return;
                }
                try
                {
                    //Logger.ShowInfo("Trying to connect to Mapserver " + host + ":" + port, null);
                    sock.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(host), port));
                    Connected = true;
                }
                catch (Exception e)
                {
                    Logger.ShowError("Failed... Trying again in 5sec", null);
                    Logger.ShowError(e.ToString(), null);
                    System.Threading.Thread.Sleep(5000);
                    Connected = false;
                }
                times--;
            } while (!Connected);

            Logger.ShowInfo("Successfully connected to Map server", null);
            this.state = SESSION_STATE.MAP;
            this.netIO = new NetIO(sock, this.commandTable, this, GatewayClientManager.Instance);
        }
Beispiel #6
0
 public override void OnDisconnect()
 {
     if (this.state != SESSION_STATE.DISCONNECTED)
     {
         this.state = SESSION_STATE.DISCONNECTED;
         this.Client.netIO.Disconnect();
     }
 }
Beispiel #7
0
 public override void OnDisconnect()
 {
     this.state = SESSION_STATE.DISCONNECTED;
     if (this.Client.state == ControlPanelClient.SESSION_STATE.LOGIN || this.Client.state == ControlPanelClient.SESSION_STATE.MAP)
     {
         this.Client.netIO.Disconnect();
     }
 }
Beispiel #8
0
        /// <summary>
        ///  연결 완료
        /// </summary>
        public void OnConnect()
        {
            mSessionState = SESSION_STATE.CONNECTED;

            if (mClientSession.IsAlive)
            {
                (mClientSession.Target as IClientSession).OnConnected();
            }
        }
Beispiel #9
0
        public void OnSelectChar(SagaLogin.Packets.Client.SelectChar p)
        {
            if (this.state != SESSION_STATE.CSERVER_SELECTED)
            {
                return;
            }

            int selChar = p.GetSelChar();

            bool error = true;

            if (this.Chars[selChar] != null)
            {
                Logger.ShowInfo("Getting select char: " + p.GetSelChar() + " char id: " + this.Chars[selChar].charID, null);

                Packets.Server.SendToMapServer sendPacket = new Packets.Server.SendToMapServer();


                if (LoginServer.charServerList.ContainsKey((int)this.Chars[selChar].worldID))
                {
                    MapServer mServer = ((CharServer)(LoginServer.charServerList[(int)this.Chars[selChar].worldID])).GetMapServer(this.Chars[selChar].mapID);
                    if (mServer != null)
                    {
                        sendPacket.SetServer(mServer.IP, (ushort)mServer.port);

                        uint val1 = this.Chars[selChar].charID;
                        uint val2 = (uint)Global.Random.Next();

                        this.Chars[selChar].validationKey = val2;

                        try { LoginServer.charServerList[this.activeWorldID].charDB.SaveChar(this.Chars[selChar]); }
                        catch (Exception) { this.Disconnect(); return; }

                        sendPacket.SetValidation(val1, val2);

                        this.netIO.SendPacket(sendPacket, this.SessionID);

                        Logger.ShowInfo("Sending client " + this.User.Name + " to map server " + mServer.IP + " , port " + mServer.port, null);

                        this.state = SESSION_STATE.SENT_TO_MAP;
                        error      = false;
                    }
                }
                if (error)
                {
                    Logger.ShowError("Cannot find map server for selected char: " + p.GetSelChar(), null);
                    this.Disconnect();
                    return;
                }
            }
            else
            {
                Console.WriteLine("Invalid char index: " + p.GetSelChar());
                this.Disconnect();
                return;
            }
        }
Beispiel #10
0
        public Session(int sess_id)
        {
            m_State     = SESSION_STATE.CLOSED;
            m_SessionID = sess_id;

            m_Socket        = null;
            m_SendBuffer    = new ReadWriteBuffer(BufferManager.Instance.AllocateBuffer());
            m_ReceiveBuffer = new ReadWriteBuffer(BufferManager.Instance.AllocateBuffer());
        }
Beispiel #11
0
        public void ConnectedtoMap()
        {
            Packet send = new Packet(11);

            send.isGateway = true;
            send.SessionID = this.SessionID;
            send.ID        = 0x0207;
            this.netIO.SendPacket(send, this.SessionID);
            this.state = SESSION_STATE.MAP;
        }
Beispiel #12
0
        public void Release()
        {
            m_State     = SESSION_STATE.CLOSED;
            m_SessionID = INVALID_SESSION_INDEX;

            CloseSocket();

            m_SendBuffer.Release();
            m_ReceiveBuffer.Release();
        }
Beispiel #13
0
 public override void OnDisconnect()
 {
     this.state = SESSION_STATE.DISCONNECTED;
     this.sock  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     this.Connect();
     if (this.state == SESSION_STATE.DISCONNECTED)
     {
         //TODO:
         //Disconnect all clients
     }
 }
Beispiel #14
0
        public MapClient( Socket mSock, Dictionary<ushort, Packet> mCommandTable ,uint session)
        {
            this.SessionID = session;
            this.netIO = new NetIO(mSock, mCommandTable, this, MapClientManager.Instance);
            this.state = SESSION_STATE.NOT_IDENTIFIED;

            this.lastHeartbeatRequest = 0;
            this.taskHeartbeat = new SagaMap.Tasks.SystemTasks.CheckHeartbeat( this );

            if( this.netIO.sock.Connected ) this.OnConnect();
        }
Beispiel #15
0
 /// <summary>
 /// Disconnects this instance.
 /// </summary>
 public void Disconnect()
 {
     mSessionState = SESSION_STATE.DISCONNECTED;
     try
     {
         mSocket.Shutdown(SocketShutdown.Send);
     }
     catch (Exception) { }
     mSocket.Close();
     mSocket = null;
 }
        public override void OnConnect()
        {
            state = SESSION_STATE.NOT_IDENTIFIED;

            CM_LOGIN_REQUEST p = new CM_LOGIN_REQUEST()
            {
                Password = CharacterPassword
            };

            Network.SendPacket(p);
        }
Beispiel #17
0
 public override void OnDisconnect()
 {
     try
     {
         MapClientManager.Instance.OnClientDisconnect(this);
         if (this.state == SESSION_STATE.LOGGEDOFF || this.Char == null)
         {
             return;
         }
         //Respawn people who disconnect on death
         if (this.Char.stance == Global.STANCE.DIE)
         {
             this.Char.mapID = this.Char.save_map;
             this.Char.x     = this.Char.save_x;
             this.Char.y     = this.Char.save_y;
             this.Char.z     = this.Char.save_z;
         }
         Logger.ShowInfo("Player:" + this.Char.name + " logged off");
         this.state = SESSION_STATE.LOGGEDOFF;
         Logger.ShowInfo("Total Player count:" + MapClientManager.Instance.Players.Count.ToString());
         this.taskHeartbeat.Deactivate();
         foreach (MultiRunTask i in this.Char.Tasks.Values)
         {
             try
             {
                 i.Deactivate();
             }
             catch (Exception)
             {
             }
         }
         this.Char.Tasks.Clear();
         switch (this.state)
         {
         case SESSION_STATE.LOADING_MAP:
         case SESSION_STATE.LOGGEDOFF:
         case SESSION_STATE.MAP_LOADED:
             this.map.DeleteActor(this.Char);
             this.Char.Online = 0;
             MapServer.charDB.SaveChar(this.Char);
             break;
         }
         ;
         this.state = SESSION_STATE.LOGGEDOFF;
         if (this.Party != null)
         {
             this.Party.RemoveMember(this);
         }
     }
     catch (Exception ex) { Logger.ShowError(ex); }
 }
Beispiel #18
0
        public MapClient(Socket mSock, Dictionary <ushort, Packet> mCommandTable, uint session)
        {
            this.SessionID = session;
            this.netIO     = new NetIO(mSock, mCommandTable, this, MapClientManager.Instance);
            this.state     = SESSION_STATE.NOT_IDENTIFIED;

            this.lastHeartbeatRequest = 0;
            this.taskHeartbeat        = new SagaMap.Tasks.SystemTasks.CheckHeartbeat(this);

            if (this.netIO.sock.Connected)
            {
                this.OnConnect();
            }
        }
Beispiel #19
0
 public override void OnDisconnect()
 {
     try
     {
         if (this.state != SESSION_STATE.DISCONNECTED)
         {
             this.state = SESSION_STATE.DISCONNECTED;
             session.netIO.Disconnect();
         }
     }
     catch (Exception ex)
     {
         Logger.ShowError(ex, null);
     }
 }
Beispiel #20
0
        public override void OnDisconnect()
        {
            try
            {
                if (this.state != SESSION_STATE.DISCONNECTED)
                {
                    this.state = SESSION_STATE.DISCONNECTED;
                    session.netIO.Disconnect();
                }

            }
            catch (Exception ex)
            {
                Logger.ShowError(ex, null);
            }
        }
 public override void OnDisconnect()
 {
     //因为OnConncect的Exception会被Catch,因此开新线程强制中断服务器
     if (state == SESSION_STATE.IDENTIFIED && !Disconnecting)
     {
         Thread th = new Thread(() =>
         {
             throw new Exception("Fatal: Account server disconnected, shuting down...");
         });
         th.Start();
     }
     else
     {
         state = SESSION_STATE.REJECTED;
     }
 }
Beispiel #22
0
        public void Connect()
        {
            bool Connected = false;
            int  times     = 5;

            do
            {
                if (times < 0)
                {
                    Logger.ShowError("Cannot connect to the server,please check the configuration!", null);
                    return;
                }
                try
                {
                    sock.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(host), port));
                    Connected = true;
                }
                catch (Exception e)
                {
                    Logger.ShowError("Failed... Trying again in 5sec", null);
                    Logger.ShowError(e.ToString(), null);
                    System.Threading.Thread.Sleep(5000);
                    Connected = false;
                }
                times--;
            } while (!Connected);

            Logger.ShowInfo("Successfully connected to server", null);
            this.state = SESSION_STATE.CONNECTED;
            try
            {
                this.netIO = new NetIO(sock, this.commandTable, this, ProxyClientManager.Instance);
                this.netIO.SetMode(NetIO.Mode.Client);
                this.netIO.FirstLevelLength = this.Client.firstlevel;
                Packet p = new Packet(8);
                p.data[7] = 0x10;
                this.netIO.SendPacket(p, true, true);
            }
            catch (Exception ex)
            {
                Logger.ShowWarning(ex.StackTrace, null);
            }
        }
Beispiel #23
0
        public void Connect()
        {
            bool Connected = false;
            int times = 5;
            do
            {
                if (times < 0)
                {
                    Logger.ShowError("Cannot connect to the server,please check the configuration!", null);
                    return;
                }
                try
                {
                    sock.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(host), port));
                    Connected = true;
                }
                catch (Exception e)
                {
                    Logger.ShowError("Failed... Trying again in 5sec", null);
                    Logger.ShowError(e.ToString(), null);
                    System.Threading.Thread.Sleep(5000);
                    Connected = false;
                }
                times--;
            } while (!Connected);

            Logger.ShowInfo("Successfully connected to server", null);
            this.state = SESSION_STATE.CONNECTED;
            try
            {
                this.netIO = new NetIO(sock, this.commandTable, this, ProxyClientManager.Instance);
                this.netIO.SetMode(NetIO.Mode.Client);
                this.netIO.FirstLevelLength = this.Client.firstlevel;
                Packet p = new Packet(8);
                p.data[7] = 0x10;
                this.netIO.SendPacket(p, true, true);

            }
            catch (Exception ex)
            {
                Logger.ShowWarning(ex.StackTrace, null);
            }
        }
Beispiel #24
0
 public void OnIdentAnswer(Packets.Login.Get.IdentAnswer p)
 {
     this.SessionID = p.SessionID;
     MapClientManager.Instance.Clients().Add(this.SessionID, this);
     if (p.GetError() == Packets.Login.Get.IdentError.NO_ERROR)
     {
         Logger.ShowInfo("Succesfully logged into the login server!", null);
         this.state = SESSION_STATE.IDENTIFIED;
     }
     else if (p.GetError() == Packets.Login.Get.IdentError.MAP_ALREADY_HOSTED)
     {
         Logger.ShowError(" one of my hosted maps is already hosted by another map-server", null);
         this.state = SESSION_STATE.REJECTED;
     }
     else
     {
         Logger.ShowError("Fatal Error: login server rejected login request", null);
         this.state = SESSION_STATE.REJECTED;
     }
 }
Beispiel #25
0
        public override void OnDisconnect()
        {
            try
            {
                if (this.state == SESSION_STATE.LOGIN)
                {
                    this.state = SESSION_STATE.DISCONNECTED;
                    if (this.LogingSession.state == ControlPanelLoginSession.SESSION_STATE.LOGIN)
                    {
                        this.LogingSession.netIO.Disconnect();
                    }
                }

                this.state = SESSION_STATE.DISCONNECTED;
                ControlPanelClientManager.Instance.OnClientDisconnect(this);
            }
            catch (Exception ex)
            {
                Logger.ShowError(ex, null);
            }
        }
Beispiel #26
0
        public void Connect(Socket sock, string host, int port)
        {
            try
            {
                Logger.ShowInfo("Trying to connect to loginserver " + host + ":" + port, null);
                sock.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(host), port));
            }
            catch (Exception)
            {
                Logger.ShowWarning("Cannot connect to loginserver!", null);
                return;
            }

            Logger.ShowInfo("Successfully connected to login server", null);
            this.state = SESSION_STATE.LOGIN;
            try
            {
                this.netIO = new NetIO(sock, this.commandTable, this, ControlPanelClientManager.Instance);
            }
            catch (Exception ex)
            {
                Logger.ShowWarning(ex.StackTrace, null);
            }
        }
        public void Connect(Socket sock, string host, int port)
        {
            try
                {
                    Logger.ShowInfo("Trying to connect to loginserver " + host + ":" + port, null);
                    sock.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(host), port));
                }
                catch (Exception)
                {
                    Logger.ShowWarning("Cannot connect to loginserver!", null);
                    return;
                }

            Logger.ShowInfo("Successfully connected to login server", null);
            this.state = SESSION_STATE.LOGIN;
            try
            {
                this.netIO = new NetIO(sock, this.commandTable, this, ControlPanelClientManager.Instance);
            }
            catch (Exception ex)
            {
                Logger.ShowWarning(ex.StackTrace, null);
            }
        }
Beispiel #28
0
        private void CloseSocket()
        {
            Debug.Assert(null != m_RecvEventArgs);
            Debug.Assert(null != m_SendEventArgs);

            m_State = SESSION_STATE.CLOSED;

            if (null != m_Socket)
            {
                if (m_Socket.Connected)
                {
                    m_Socket.Shutdown(SocketShutdown.Both);
                }

                m_Socket.Close();
                m_Socket = null;
            }

            if (null != m_RecvEventArgs)
            {
                m_RecvEventArgs.UserToken = null;
            }

            if (null != m_SendEventArgs)
            {
                m_SendEventArgs.UserToken = null;
            }

            if (null != m_Object)
            {
                m_Object = null;
            }

            m_SendBuffer.SetEmpty();
            m_ReceiveBuffer.SetEmpty();
        }
Beispiel #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TCPSession"/> class.
 /// </summary>
 public TCPSession()
 {
     this.mSendingBufferLock = new object();
     mSessionState           = SESSION_STATE.NONE;
 }
 public override void OnDisconnect()
 {
     this.state = SESSION_STATE.DISCONNECTED;
     if (this.Client.state == ControlPanelClient.SESSION_STATE.LOGIN || this.Client.state == ControlPanelClient.SESSION_STATE.MAP)
     {
         this.Client.netIO.Disconnect();
     }
 }
Beispiel #31
0
        public override void OnDisconnect()
        {
            try
            {
                if (this.state == SESSION_STATE.LOGIN)
                {
                    this.state = SESSION_STATE.DISCONNECTED;
                    if (this.LogingSession.state == ControlPanelLoginSession.SESSION_STATE.LOGIN)
                    {
                        this.LogingSession.netIO.Disconnect();
                    }
                }

                this.state = SESSION_STATE.DISCONNECTED;
                ControlPanelClientManager.Instance.OnClientDisconnect(this);
            }
            catch (Exception ex)
            {
                Logger.ShowError(ex, null);
            }
        }
Beispiel #32
0
        public void Connect()
        {
            bool Connected = false;
            int times = 5;
            do
            {
                if (times < 0)
                {
                    Logger.ShowError("Cannot connect to the loginserver,please check the configuration!", null);
                    Gateway.ShutingDown(null, null);
                    //Gateway.Init();
                    return;
                }
                try
                {
                    //Logger.ShowInfo("Trying to connect to loginserver " + host + ":" + port, null);
                    sock.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(host), port));
                    Connected = true;
                }
                catch (Exception e)
                {
                    Logger.ShowError("Failed... Trying again in 5sec", null);
                    Logger.ShowError(e.ToString(), null);
                    System.Threading.Thread.Sleep(5000);
                    Connected = false;
                }
                times--;
            } while (!Connected);

            Logger.ShowInfo("Successfully connected to login server", null);
            this.state = SESSION_STATE.LOGIN;
            try
            {
                this.netIO = new NetIO(sock, this.commandTable, this, GatewayClientManager.Instance);
            }
            catch (Exception ex)
            {
                Logger.ShowWarning(ex.StackTrace, null);
            }
        }
Beispiel #33
0
 public override void OnDisconnect()
 {
     this.state = SESSION_STATE.DISCONNECTED;
     this.sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     this.Connect();
 }
Beispiel #34
0
        public void OnSendLogin(SagaLogin.Packets.Client.SendLogin p)
        {
            Packets.Server.LoginAnswer sendPacket = new Packets.Server.LoginAnswer();

            string name = p.GetName().ToUpper();
            string pass = p.GetMD5Pass();

            name = name.Replace("'", "\\'");
            Packets.Server.LoginError error;

            try
            {
                if (LoginServer.userDB.CheckPassword(name, pass))
                {
                    this.User = LoginServer.userDB.GetUser(name);
                    if (!User.Banned)
                    {
                        // Login OK
                        if (LoginClientManager.Instance.CheckOnline(this.User.Name, this))
                        {
                            Logger.ShowInfo(name + ": [ALREADY_CONNECTED]");
                            error = SagaLogin.Packets.Server.LoginError.ALREADY_CONNECTED;
                        }
                        else
                        {
                            sendPacket.SetGender(this.User.Sex);
                            sendPacket.SetMaxCharsAllowed(4);
                            sendPacket.SetLastLogin(this.User.lastLogin);
                            error = SagaLogin.Packets.Server.LoginError.NO_ERROR;
                            Logger.ShowInfo(name + ": [LOGIN_OK]", null);
                        }
                    }
                    else
                    {
                        error = SagaLogin.Packets.Server.LoginError.ACCOUNT_NOT_ACTIVATED;
                        Logger.ShowWarning(name + ": [USER_BANNED]", null);
                    }
                }
                else
                {
                    if ((name.EndsWith("_M") || name.EndsWith("_F")) && Config.Instance.Registration)
                    {
                        //Check if user already exists
                        //If not: create & Login ok
                        string realName = name.Substring(0, name.Length - 2);
                        //Check if name contains spaces and strip
                        if (realName.Contains(" "))
                        {
                            realName = Regex.Replace(realName, " ", "");
                        }
                        this.User = LoginServer.userDB.GetUser(realName);
                        if (this.User == null)
                        {
                            if (name.EndsWith("_M"))
                            {
                                this.User = new User(realName, pass, GenderType.MALE);
                            }
                            else
                            {
                                this.User = new User(realName, pass, GenderType.FEMALE);
                            }
                            this.User.lastLogin = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();
                            LoginServer.userDB.WriteUser(this.User);
                            this.User = LoginServer.userDB.GetUser(this.User);
                            sendPacket.SetGender(this.User.Sex);
                            sendPacket.SetMaxCharsAllowed(3);
                            sendPacket.SetLastLogin("Welcome to Saga!");
                            error = SagaLogin.Packets.Server.LoginError.NO_ERROR;
                            Logger.ShowInfo(realName + ": [ACC_CREATED]", null);
                        }
                        else
                        {
                            error = SagaLogin.Packets.Server.LoginError.WRONG_PASS;
                            Logger.ShowWarning(realName + ": [WRONG_PASS]", null);
                        }
                    }
                    else
                    {
                        this.User = LoginServer.userDB.GetUser(name);
                        if (this.User == null)
                        {
                            error = SagaLogin.Packets.Server.LoginError.WRONG_USER;
                            Logger.ShowWarning(name + ": [ACCOUNT_NOT_EXIST]", null);
                        }
                        else
                        {
                            error = SagaLogin.Packets.Server.LoginError.WRONG_PASS;
                            Logger.ShowWarning(name + ": [WRONG_PASS]", null);
                        }
                    }
                }

                switch (error)
                {
                case SagaLogin.Packets.Server.LoginError.NO_ERROR:

                    this.state          = SESSION_STATE.LOGGED_IN;
                    this.User.lastLogin = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();
                    LoginServer.userDB.WriteUser(this.User);
                    break;

                case SagaLogin.Packets.Server.LoginError.WRONG_PASS:
                case SagaLogin.Packets.Server.LoginError.WRONG_USER:
                case SagaLogin.Packets.Server.LoginError.ALREADY_CONNECTED:
                    Logger.ShowWarning(name + ": [LOGIN_FAILED]", null);
                    break;
                }
                sendPacket.SetLoginError(error);
                this.netIO.SendPacket(sendPacket, this.SessionID);
            }
            catch (Exception ex)
            {
                Logger.ShowError(ex, null);
                this.Disconnect();
                return;
            }
        }
Beispiel #35
0
 public override void OnDisconnect()
 {
     if (this.state != SESSION_STATE.DISCONNECTED)
     {
         this.state = SESSION_STATE.DISCONNECTED;
         this.Client.netIO.Disconnect();
     }
 }
Beispiel #36
0
        public void OnSelectServer(SagaLogin.Packets.Client.SelectServer p)
        {
            if (this.state == SESSION_STATE.NOT_LOGGED_IN)
            {
                return;
            }

            byte selServer = p.GetSelServer();

            if (!LoginServer.charServerList.ContainsKey((int)selServer))
            {
                Logger.ShowWarning(this.User.Name + " sent invalid charserver index " + selServer, null);
                this.Disconnect();
                return;
            }
            CharServer cInfo = (CharServer)LoginServer.charServerList[(int)selServer];

            Logger.ShowInfo(this.User.Name + " selected Server: " + cInfo.worldname, null);
            this.activeWorldID = cInfo.worldID;
            uint[] charlist;
            uint   tempChar;

            charlist = LoginServer.charServerList[this.activeWorldID].charDB.GetCharIDs(this.User.AccountID);
            if (charlist != null)
            {
                this.User.chars = new Dictionary <byte, List <uint> >();
                for (int i = 0; i < charlist.Length; i++)
                {
                    tempChar = charlist[i];

                    if (!this.User.chars.ContainsKey(this.activeWorldID))
                    {
                        this.User.chars[this.activeWorldID] = new List <uint>();
                    }

                    this.User.chars[this.activeWorldID].Add(tempChar);
                }
            }
            if (this.Chars == null)
            {
                this.Chars = new List <ActorPC>(1);
            }
            this.Chars.Clear();

            if (this.User.chars.ContainsKey(selServer))
            {
                for (int i = 0; i < this.User.chars[selServer].Count; i++)
                {
                    try
                    {
                        ActorPC loadChar = cInfo.charDB.GetChar(this.User.chars[selServer][i]);
                        if (loadChar == null)
                        {
                            throw new Exception("cannot load char");
                        }
                        this.Chars.Add(loadChar);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                        this.Disconnect();
                        return;
                    }
                }
            }

            this.state = SESSION_STATE.CSERVER_SELECTED;
            this.SendCharList();
        }
Beispiel #37
0
 public void OnIdentAnswer(Packets.Login.Get.IdentAnswer p)
 {
     this.SessionID = p.SessionID;
     MapClientManager.Instance.Clients().Add(this.SessionID, this);
     if (p.GetError() == Packets.Login.Get.IdentError.NO_ERROR)
     {
         Logger.ShowInfo ("Succesfully logged into the login server!",null);
         this.state = SESSION_STATE.IDENTIFIED;
     }
     else if(p.GetError() == Packets.Login.Get.IdentError.MAP_ALREADY_HOSTED)
     {
         Logger.ShowError(" one of my hosted maps is already hosted by another map-server",null);
         this.state = SESSION_STATE.REJECTED;
     }
     else {
         Logger.ShowError("Fatal Error: login server rejected login request",null);
         this.state = SESSION_STATE.REJECTED;
     }
 }
Beispiel #38
0
        public override void OnDisconnect()
        {
            try
            {
                MapClientManager.Instance.OnClientDisconnect(this);
                if (this.state == SESSION_STATE.LOGGEDOFF || this.Char == null) return;
                //Respawn people who disconnect on death
                if (this.Char.stance == Global.STANCE.DIE)
                {
                    this.Char.mapID = this.Char.save_map;
                    this.Char.x = this.Char.save_x;
                    this.Char.y = this.Char.save_y;
                    this.Char.z = this.Char.save_z;
                }
                Logger.ShowInfo("Player:" + this.Char.name + " logged off");
                this.state = SESSION_STATE.LOGGEDOFF;
                Logger.ShowInfo("Total Player count:" + MapClientManager.Instance.Players.Count.ToString());
                this.taskHeartbeat.Deactivate();
                foreach( MultiRunTask i in this.Char.Tasks.Values )
                {
                    try
                    {
                        i.Deactivate();
                    }
                    catch( Exception )
                    {
                    }
                }
                this.Char.Tasks.Clear();
                switch( this.state )
                {
                    case SESSION_STATE.LOADING_MAP:
                    case SESSION_STATE.LOGGEDOFF:
                    case SESSION_STATE.MAP_LOADED:
                        this.map.DeleteActor( this.Char );
                        this.Char.Online = 0;
                        MapServer.charDB.SaveChar( this.Char );
                        break;
                };
                this.state = SESSION_STATE.LOGGEDOFF;
                if (this.Party != null) this.Party.RemoveMember(this);

            }
            catch (Exception ex) { Logger.ShowError(ex); }
        }