private void OnLogin(RelayPacket cpkt)
        {
            LoginSession session;
            if (LoginSessionHandler.sessions.TryGetValue(cpkt.SessionId, out session))
            {
                ServerInfo2 info;
                if (!ServerManager2.Instance.server.TryGetValue(session.World, out info))
                {
                    Trace.TraceError(string.Format("Server not found: {0}", session.World));
                }
                else if (info.client == null || info.client.IsConnected == false)
                {
                    Trace.TraceError(string.Format("World server not connected: {0}", session.World));
                }
                else
                {
                    Singleton.Database.UpdateSession(session.playerid, cpkt.SessionId);
                    Singleton.Database.UpdateLastplayerWorld(session.playerid, session.World);
                    info.Players++;

                    SMSG_LOGIN spkt = new SMSG_LOGIN();
                    spkt.GmLevel = session.GmLevel;
                    spkt.Gender = (byte)session.Gender;
                    spkt.CharacterId = session.characterid;
                    spkt.SessionId = cpkt.SessionId;
                    this.Send((byte[])spkt);

                    //Send login packet to world
                    /*
                    SMSG_CHARACTERLOGIN spkt2 = new SMSG_CHARACTERLOGIN();
                    spkt2.CharacterId = session.characterid;
                    spkt2.SessionId = cpkt.SessionId;
                    spkt2.Session = cpkt.SessionId;
                    info.client.Send((byte[])spkt2);*/
                }
            }
        }
Exemple #2
0
        private void ConnectToWorldServer(CMSG_ESTABLISHWORLDCONNECTION cpkt)
        {
            GatewayClient client;
            uint session = cpkt.SessionId;

            if (GatewayPool.Instance.lookup.TryGetValue(session, out client))
            {
                try
                {
                    IPAddress address = new IPAddress(cpkt.IPAddres);
                    int port = cpkt.Port;

                    Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    sock.Connect(address, port);
                    WorldClient instance = new WorldClient(sock);
                    client.world = instance;

                    RelayPacket pkt = new RelayPacket();
                    pkt.Cmd = 0x0301;
                    pkt.Id = 0x0110;
                    pkt.SessionId = session;
                    this.Send((byte[])pkt);

                    byte[] buffer2 = new byte[] {
                         0x0B, 	0x00, 	0x74, 	0x17, 	0x91, 	0x00,
                         0x02, 	0x07, 	0x00, 	0x00, 	0x00
                    };

                    Array.Copy(BitConverter.GetBytes(session), 0, buffer2, 2, 4);
                    client.Send(buffer2);
                }
                catch (Exception)
                {
                    byte[] buffer2 = new byte[] {
                         0x0B, 	0x00, 	0x74, 	0x17, 	0x91, 	0x00,
                         0x02, 	0x07, 	0x00, 	0x00, 	0x01
                    };
                    Array.Copy(BitConverter.GetBytes(session), 0, buffer2, 2, 4);
                    client.Send(buffer2);
                }
            }
        }
        /*
        internal void Login_Callback(uint sessionId, string username, string password)
        {
            LoginSession session;
            if (LoginSessionHandler.sessions.TryGetValue(sessionId, out session))
            {
                LoginResult result;
                LoginError error = LoginError.NO_ERROR;
                DateTime LastLogin = DateTime.Now;

                try
                {
                    if (Singleton.Database.Login(username.ToLowerInvariant(), out result))
                    {
                        #region PASSWORD VERIFYCATION

                        //CHECKS IF THE PASSWORD IS CORRECT
                        if (!result.lg_password.StartsWith(password))
                        {
                            Trace.TraceWarning("Wrong password");
                            error = LoginError.WRONG_PASS;
                        }

                        #endregion PASSWORD VERIFYCATION

                        #region CHECK AGREEMENT

                        //CHECK IF PLAYER HAS AGREED TERMS
                        else if (!result.has_agreed)
                        {
                            Trace.TraceWarning("Account not agreed with agreement");
                            error = LoginError.CONFIRM_AGGEEMENT;
                        }

                        #endregion CHECK AGREEMENT

                        #region CHECK ACTIVATION

                        //CHECK IF ACCOUNT IS ACTIVATED
                        else if (!result.is_activated)
                        {
                            Trace.TraceWarning("Account not activated");
                            error = LoginError.ACCOUNT_NOT_ACTIVATED;
                        }

                        #endregion CHECK ACTIVATION

                        #region CHECK BANNED

                        //CHECK IF ACCOUNT IS BANNED
                        else if (result.is_banned == true)
                        {
                            Trace.TraceWarning("Account is banned");
                            error = LoginError.ACCOUNT_SUSSPENDED;
                        }

                        #endregion CHECK BANNED

                        #region TEST ENVIRMONT VERIFYCATION

                        //CHECK IF THE SERVER IS IN TESTMODE AND THE USER CAN LOGIN (GM'S)
                        else if (Saga.Managers.ConsoleCommands.InTestmode && result.is_testaccount == false)
                        {
                            Trace.TraceWarning("Not a test account");
                            error = LoginError.NOT_TEST_ACCOUNT;
                        }

                        #endregion TEST ENVIRMONT VERIFYCATION

                        #region CHECK ACTIVE SESSION

                        else if (result.ative_session > 0)
                        {
                            Trace.TraceWarning("Already connected");
                            error = LoginError.ALREADY_CONNECTED;
                            session.playerid = result.userid;
                            session.ActiveSession = result.ative_session;
                            session.LastPlayedWorld = (byte)result.last_server;
                        }

                        #endregion CHECK ACTIVE SESSION

                        #region LOGIN SUCESS

                        //ELSE SET THE USER ID
                        else
                        {
                            LastLogin = result.lg_entry;
                            session.GmLevel = result.gmlevel;
                            session.Gender = result.lg_gender;
                            session.playerid = result.userid;
                            session.Age = (byte)Utillities.CalculateAge(result.DateOfBirth);
                            Singleton.Database.UpdateLoginEntry(session.playerid);
                        }

                        #endregion LOGIN SUCESS
                    }
                    else
                    {
                        #region USERNAME VERIFICATION

                        //USERNAME DOES NOT EXISTS
                        error = LoginError.WRONG_USER;

                        #endregion USERNAME VERIFICATION
                    }
                }
                catch (Exception e)
                {
                    Trace.TraceError("Database error");
                    error = LoginError.DATABASE_ERROR;
                }
                try
                {
                    SMSG_LOGINAWNSER spkt = new SMSG_LOGINAWNSER();
                    spkt.Gender = (byte)session.Gender;
                    spkt.LastLogin = LastLogin;
                    spkt.LoginError = error;
                    spkt.MaxChars = (byte)session.NMaxCharacters;
                    spkt.SessionId = sessionId;
                    spkt.Advertisment = (byte)((Saga.Managers.ConsoleCommands.ShowAdvertisment) ? 1 : 0);
                    this.Send((byte[])spkt);
                }
                catch (Exception)
                {
                    this.Close();
                }
            }
        }
        */
        private void CM_KILLEXISTINGCONNECTION(RelayPacket packet)
        {
            ServerInfo2 info;
            LoginSession session;
            if (LoginSessionHandler.sessions.TryGetValue(packet.SessionId, out session))
                if (ServerManager2.Instance.server.TryGetValue(session.LastPlayedWorld, out info)
                && info.client != null && info.client.IsConnected)
                {
                    //Clears the active session
                    info.client.SM_KILLSESSION(session.ActiveSession);
                }
                else
                {
                    Trace.TraceWarning("World was not found release session");

                    //If world was not found
                    Singleton.Database.ReleaseSessionId(session.ActiveSession);
                }
        }
Exemple #4
0
 private void ForwardToAll(RelayPacket spkt)
 {
     //Send over movement start to all characters in neighbourhood
     foreach (MapObject c in this.currentzone.GetObjectsInRegionalRange(this))
         if (MapObject.IsPlayer(c))
         {
             spkt.SessionId = c.id;
             Character character = c as Character;
             character.client.Send((byte[])spkt);
         }
 }