Exemplo n.º 1
0
        private PacketContent LogoutAction(SerializedInfo request, Token token)
        {
            PacketContent result = LoginOutService.Logout(request.ClientInfo.Session);

            if (token.AppType == AppType.Mobile)
            {
                Mobile.Manager.Logout(token);
            }
            return(result);
        }
Exemplo n.º 2
0
 public static List <string> Parse(PacketContent content)
 {
     if (content.ContentType == ContentType.Xml)
     {
         return(ParseXml(content.XmlContent));
     }
     else if (content.ContentType == ContentType.Json)
     {
         return(ParseJson(content.JsonContent.Request));
     }
     else
     {
         throw new NotSupportedException();
     }
 }
Exemplo n.º 3
0
 public static bool Received(AuthenticationServer form, PacketContent pc, Candidate c)
 {
     _form = form;
     PlayerRecvPackets msgType = (PlayerRecvPackets)pc.GetMsgType();
     bool ret = true;
     switch (msgType)
     {
         case PlayerRecvPackets.Login:
             ret = CheckCredentials(pc, c);
             break;
         case PlayerRecvPackets.ServerSelect:
             ret = PassNewPlayerToServer(pc, c);
             break;
     }
     return ret;
 }
Exemplo n.º 4
0
        public static PacketContent Recover(Session originSession, Session currentSession)
        {
            PacketContent result = XmlResultHelper.ErrorResult;

            try
            {
                if (Application.Default.AgentController.RecoverConnection(originSession, currentSession))
                {
                    result = XmlResultHelper.NewResult(StringConstants.OkResult).ToPacketContent();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                _Logger.Error(ex);
            }
            return(result);
        }
Exemplo n.º 5
0
        private void PopulatePacketContent(Packet packet)
        {
            var ipPacket = packet.IpPacket;

            switch (ipPacket.Protocol)
            {
            case ProtocolType.Tcp:
                var tcpPacket = ipPacket.Extract <TcpPacket>();
                if (tcpPacket != null)
                {
                    PacketContent.Add(new TcpPacketTemplate(tcpPacket));
                }
                break;

            case ProtocolType.Udp:
                var udpPacket = ipPacket.Extract <UdpPacket>();
                if (udpPacket != null)
                {
                    PacketContent.Add(new UdpPacketTemplate(udpPacket));
                }
                break;

            case ProtocolType.IcmpV6:
                var icmpv6Packet = ipPacket.Extract <IcmpV6Packet>();
                if (icmpv6Packet != null)
                {
                    PacketContent.Add(new IcmpV6PacketTemplate(icmpv6Packet));
                }
                break;

            case ProtocolType.Igmp:
                var igmpPacket = ipPacket.Extract <IgmpV2Packet>();
                if (igmpPacket != null)
                {
                    PacketContent.Add(new IgmpPacketTemplate(igmpPacket));
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 6
0
        private void ProcessRequest(SerializedInfo request)
        {
            PacketContent responseContent = null;

            try
            {
                ContentType       contentType = request.Content.ContentType;
                IRequestProcessor requestProcessor;
                if (contentType == ContentType.KeepAlivePacket)
                {
                    requestProcessor = KeepAliveProcessor.Default;
                }
                else if (contentType == ContentType.Xml)
                {
                    requestProcessor = XmlProcessor.Default;
                }
                else if (contentType == ContentType.Json)
                {
                    requestProcessor = JsonProcessor.Default;
                }
                else
                {
                    throw new NotSupportedException();
                }
                responseContent = requestProcessor.Process(request);
            }
            catch (Exception ex)
            {
                responseContent = XmlResultHelper.NewErrorResult(ex.ToString()).ToPacketContent();
            }
            finally
            {
                Application.Default.SessionMonitor.Update(request.ClientInfo.Session);
                if (responseContent != null)
                {
                    request.UpdateContent(responseContent);
                    SendCenter.Default.Send(request);
                }
            }
        }
Exemplo n.º 7
0
        private void PopulatePacketContent(Packet packet)
        {
            var ipPacket = packet.IpPacket;

            switch (ipPacket.Version)
            {
            case PacketDotNet.IPVersion.IPv4:
                var ipv4Header = new IPv4HeaderTemplate(packet);
                PacketContent.Add(ipv4Header);
                PacketContent.AddRange(ipv4Header.PacketContent);
                break;

            case PacketDotNet.IPVersion.IPv6:
                var ipv6Header = new IPv6HeaderTemplate(packet);
                PacketContent.Add(ipv6Header);
                PacketContent.AddRange(ipv6Header.PacketContent);
                break;

            default:
                break;
            }
        }
Exemplo n.º 8
0
 private static bool PassNewPlayerToServer(PacketContent pc, Candidate c)
 {
     bool ret = true;
     if (c.socket == null) return false;
     c.loginToken = RandomString(16);
     c.selectedServerIndex = pc.ReadLong();
     ret = GameServer.RegisterNewPlayer(c.selectedServerIndex, c.loginName, c.loginToken, ref c.player, ref c.playerBank);
     if (!ret)
     {
         string ipAddress = ((IPEndPoint)c.socket.RemoteEndPoint).Address.ToString();
         AppendLog(c.loginName + "/" + ipAddress +  "is trying to login, but there's no available servers for him to join.");
         SendClient_AlertMsg(c.socket, "Server is down, try again in a minute!", true);
         KillClientSocket(c);
     }
     return ret;
 }
Exemplo n.º 9
0
 private static bool CheckCredentials(PacketContent pc, Candidate c)
 {
     if (c.socket == null) return false;
     IPEndPoint clientInfo = (IPEndPoint)c.socket.RemoteEndPoint;
     AppendLog(clientInfo.Address.ToString() + " is trying to login...");
     c.loginName = pc.ReadString();
     c.password = pc.ReadString();
     int appMajor = pc.ReadLong();
     int appMinor = pc.ReadLong();
     int appRev = pc.ReadLong();
     DecryptPassword(c);
     if (appMajor != _form.getMajor() || appMinor != _form.getMinor() || appRev != _form.getRevision())
     {
         AppendLog(clientInfo.Address.ToString() + " has an outdated version of the client (" + appMajor + "." + appMinor + "." + appRev + "). Rejecting...");
         SendClient_AlertMsg(c.socket, "Old version detected, run the updater and try again!", true);
         KillClientSocket(c);
         return false;
     }
     return CheckPlayerStatus(c);
 }
 private static void ExecuteRequestWhenSessionNotExist(string methodName, SerializedInfo request, Token token, out PacketContent result)
 {
     result = XmlResultHelper.ErrorResult;
     if (methodName == LoginMethodName)
     {
         result = RequestTable.Default.Execute(methodName, request, token);
     }
     if (request.ClientInfo.ClientId != Session.InvalidSession)
     {
         request.ClientInfo.UpdateSession(request.ClientInfo.ClientId);
     }
 }