Example #1
0
        public void OnWantServerList(Packets.Client.WantServerList p)
        {
            if (this.state == SESSION_STATE.NOT_LOGGED_IN)
            {
                return;
            }

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

            foreach (CharServer cInfo in LoginServer.charServerList.Values)
            {
                short charCount = 0;
                try
                {
                    charCount = (short)LoginServer.charServerList[cInfo.worldID].charDB.GetCharIDs(this.User.AccountID).Length;
                }
                catch (Exception)
                {
                    charCount = (short)this.User.chars.Count;
                }
                if (cInfo.mapServers.Count == 0)
                {
                    cInfo.ping = CharServer.Status.MAINTENANCE;
                }
                else
                {
                    MapServer server = cInfo.mapServers[0];
                    if (server.lastPong < server.lastPing)
                    {
                        cInfo.ping = CharServer.Status.MAINTENANCE;
                    }
                    else
                    {
                        TimeSpan span = server.lastPong - server.lastPing;
                        if (span.TotalMilliseconds < 50)
                        {
                            cInfo.ping = CharServer.Status.OK;
                        }
                        else if (span.TotalMilliseconds < 300)
                        {
                            cInfo.ping = CharServer.Status.CROWDED;
                        }
                        else if (span.TotalMilliseconds >= 300)
                        {
                            cInfo.ping = CharServer.Status.OVERLOADED;
                        }
#if Preview_Version
                        if (LoginClientManager.Instance.clients.Count > 15)
                        {
                            cInfo.ping = CharServer.Status.OVERLOADED;
                        }
#endif
                    }
                }
                sendPacket.AddServer(cInfo.worldID, cInfo.worldname, charCount, cInfo.ping);
            }

            this.netIO.SendPacket(sendPacket, this.SessionID);
        }
Example #2
0
        public void OnMapIdentify(Packets.Map.Get.Identify p)
        {
            if (this.state != SESSION_STATE.NOT_LOGGED_IN)
            {
                return;
            }

            string serverPass = p.GetPass();
            string serverName = p.GetWorldName();

            Logger.ShowInfo("new map server connected, worldname: " + serverName, null);

            Packets.Map.Send.LoginAnswer sendPacket = new Packets.Map.Send.LoginAnswer();

            bool validServer         = false;
            bool aMapIsAlreadyHosted = false;

            if (serverPass == LoginServer.lcfg.MapServerPass)
            {
                foreach (CharServer cServer in LoginServer.charServerList.Values)
                {
                    if (cServer.worldname == serverName)
                    {
                        if (cServer.MapsAreNotHostedYet(p.GetHostedMaps()))
                        {
                            validServer = true;
                            MapServer newServer = new MapServer(cServer.worldID, p.GetIP(), p.GetPort(), this, p.GetHostedMaps(), 0, 0);
                            cServer.AddMapServer(newServer);
                            this.mapServer        = newServer;
                            this.MapWorldIndex    = cServer.worldID;
                            this.isMapServer      = true;
                            this.heartbeatService = new MapHeartbeat(this);
                            this.heartbeatService.Activate();
                        }
                        else
                        {
                            aMapIsAlreadyHosted = true;
                        }
                    }
                }
            }

            if (validServer)
            {
                sendPacket.SetError(Packets.Map.Send.IdentError.NO_ERROR);
                Console.WriteLine("map-server " + serverName + " : [LOGIN_OK]");
            }
            else if (aMapIsAlreadyHosted)
            {
                sendPacket.SetError(Packets.Map.Send.IdentError.MAP_ALREADY_HOSTED);
                Console.WriteLine("map-server " + serverName + " : [LOGIN_FAILED] map-server tried to host a map which is already hosted by another map-server");
            }
            else
            {
                sendPacket.SetError(Packets.Map.Send.IdentError.ERROR);
                Console.WriteLine("map-server " + serverName + " : [LOGIN_FAILED]");
            }
            this.netIO.SendPacket(sendPacket, this.SessionID);
        }
Example #3
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;
            }
        }
Example #4
0
 public void DeleteMapServer(MapServer delServer)
 {
     this.mapServers.Remove(delServer);
 }
Example #5
0
 public void AddMapServer(MapServer newServer)
 {
     this.mapServers.Add(newServer);
 }
Example #6
0
 public void DeleteMapServer(MapServer delServer)
 {
     this.mapServers.Remove(delServer);
 }
Example #7
0
 public void AddMapServer(MapServer newServer)
 {
     this.mapServers.Add(newServer);
 }