GetServerByEndPoint() публичный статический Метод

public static GetServerByEndPoint ( string ip, int port ) : SRX_Serverinfo
ip string
port int
Результат SRX_Serverinfo
Пример #1
0
        public void OnIPC(Socket aSocket, EndPoint ep, byte[] data)
        {
            try
            {
                if (data.Length >= 6)
                {
                    /*string str;
                     * System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                     * str = enc.GetString(data);*/

                    string[] ip_s = ep.ToString().Split(':');

                    Systems.SRX_Serverinfo remoteGameServer = Systems.GetServerByEndPoint(ip_s[0], UInt16.Parse(ip_s[1]));
                    if (remoteGameServer != null)
                    {
                        // decode data
                        //Network.Servers.IPCdeCode(ref data, remoteGameServer.code);

                        Systems.PacketReader pack = new Systems.PacketReader(data);
                        short pcmd = pack.Int16();
                        if (data.Length >= 6)
                        {
                            switch (pcmd)
                            {
                            default:
                                LogDebug.Show("[IPC] unknown command recevied {0:x}", pcmd);
                                break;
                            }
                        }
                        else
                        {
                            LogDebug.Show("[IPC] data to short");
                        }
                    }
                    else
                    {
                        LogDebug.Show("[IPC] can't find the GameServer {0}:{1}", ((IPEndPoint)ep).Address.ToString(), ip_s[1]);
                    }
                }
                else
                {
                    LogDebug.Show("[IPC] packet to short from {0}", ep.ToString());
                }
            }
            catch (Exception ex)
            {
                LogDebug.Show("[IPC.OnIPC] {0}", ex);
            }
        }
Пример #2
0
        //IPC & Data
        #region IPC & Data
        public void OnIPC(System.Net.Sockets.Socket aSocket, System.Net.EndPoint ep, byte[] data)
        {
            try
            {
                if (data.Length >= 6)
                {
                    UInt16 pServer = (UInt16)(data[0] + (data[1] << 8));
                    Systems.SRX_Serverinfo remoteGameServer = Systems.GetServerByEndPoint(((IPEndPoint)ep).Address.ToString(), pServer);
                    if (remoteGameServer != null)
                    {
                        // decode data
                        Servers.IPCdeCode(ref data, remoteGameServer.code);

                        byte pCmd = data[3];
                        int  dLen = (int)(data[4] + (data[5] << 8));
                        byte crc  = Servers.BCRC(data, data.Length - 1);
                        if (data[data.Length - 1] != crc) // wrong CRC
                        {
                            Activity("[ERROR] Code for: " + remoteGameServer.name + " does not match");
                            return;
                        }
                        if (data.Length >= (dLen + 6))
                        {
                            if (pCmd == (byte)IPCCommand.IPC_INFO_SERVER)
                            {
                                if (data.Length >= 11)
                                {
                                    remoteGameServer.maxSlots  = (UInt16)(data[7] + (data[8] << 8));
                                    remoteGameServer.usedSlots = (UInt16)(data[9] + (data[10] << 8));
                                    remoteGameServer.lastPing  = DateTime.Now;
                                    Activity("[NET] " + remoteGameServer.name + ": players online " + remoteGameServer.usedSlots + "/" + remoteGameServer.maxSlots + "");
                                    if (remoteGameServer.status == 0 && data[6] != 0)
                                    {
                                        Activity("[NET] Server: " + remoteGameServer.name + " is now online");
                                    }
                                    if (remoteGameServer.status != 0 && data[6] == 0)
                                    {
                                        Activity("[NET] Server: " + remoteGameServer.name + " is now in check state");
                                    }
                                    remoteGameServer.status = data[6];
                                }
                                else
                                {
                                }
                            }
                            else if (pCmd == (byte)IPCCommand.IPC_INFO_LOGIN)
                            {
                                if (dLen >= 4)
                                {
                                    UInt16 IPCid     = (UInt16)(data[6] + (data[7] << 8));
                                    UInt16 IPCResult = (UInt16)(data[8] + (data[9] << 8));
                                    byte   sLen      = data[10];
                                    lock (IPCResultList)
                                    {
                                        if (IPCResultList.ContainsKey(IPCid))
                                        {
                                            IPCResultList[IPCid].resultCode = IPCResult;
                                            if (sLen > 0)
                                            {
                                                IPCResultList[IPCid].banReason = System.Text.ASCIIEncoding.ASCII.GetString(data, 11, sLen);
                                            }
                                        }
                                        else
                                        {
                                            Activity("[ERROR] ResultList mismatch");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Activity("[ERROR] unknown command recevied");
                            }
                        }
                        else
                        {
                            Activity("[ERROR] data to short");
                        }
                    }
                    else
                    {
                        Activity("[ERROR] can't find the GameServer " + ((IPEndPoint)ep).Address.ToString() + "");
                    }
                }
                else
                {
                    Activity("[ERROR] packet to short from " + ep.ToString() + "");
                }
            }
            catch (Exception ex)
            {
                Activity("[ERROR] " + ex + "");
            }
        }
Пример #3
0
        public void OnIPC(System.Net.Sockets.Socket aSocket, System.Net.EndPoint ep, byte[] data)
        {
            try
            {
                if (data.Length >= 6)
                {
                    UInt16 pServer = (UInt16)(data[0] + (data[1] << 8));
                    Systems.SRX_Serverinfo remoteGameServer = Systems.GetServerByEndPoint(((IPEndPoint)ep).Address.ToString(), pServer);
                    if (remoteGameServer != null)
                    {
                        // decode data
                        Servers.IPCdeCode(ref data, remoteGameServer.code);

                        byte pCmd = data[3];
                        int  dLen = (int)(data[4] + (data[5] << 8));
                        byte crc  = Servers.BCRC(data, data.Length - 1);
                        if (data[data.Length - 1] != crc) // wrong CRC
                        {
                            Console.WriteLine("{1} Wrong Checksum for Server {0}", remoteGameServer.name, Product.Prefix);
                            return;
                        }
                        if (data.Length >= (dLen + 6))
                        {
                            if (pCmd == (byte)IPCCommand.IPC_INFO_SERVER)
                            {
                                if (data.Length >= 11)
                                {
                                    remoteGameServer.maxSlots  = (UInt16)(data[7] + (data[8] << 8));
                                    remoteGameServer.usedSlots = (UInt16)(data[9] + (data[10] << 8));
                                    remoteGameServer.lastPing  = DateTime.Now;
                                    //Console.WriteLine("[IPC] Received SERVER-INFO from GameServer {1} ({0}): S={2}, MAX={3}, CUR={4}", remoteGameServer.name, remoteGameServer.id, data[6], remoteGameServer.maxSlots, remoteGameServer.usedSlots);
                                    if (remoteGameServer.status == 0 && data[6] != 0)
                                    {
                                        Console.WriteLine("{2}GameServer {0} ({1}) status changed to online", remoteGameServer.id, remoteGameServer.name, Product.Prefix);
                                    }
                                    if (remoteGameServer.status != 0 && data[6] == 0)
                                    {
                                        Console.WriteLine("{2}GameServer {0} ({1}) status changed to check", remoteGameServer.id, remoteGameServer.name, Product.Prefix);
                                    }
                                    remoteGameServer.status = data[6];
                                }
                                else
                                {
                                }
                            }
                            else if (pCmd == (byte)IPCCommand.IPC_INFO_LOGIN)
                            {
                                if (dLen >= 4)
                                {
                                    UInt16 IPCid     = (UInt16)(data[6] + (data[7] << 8));
                                    UInt16 IPCResult = (UInt16)(data[8] + (data[9] << 8));
                                    byte   sLen      = data[10];
                                    lock (IPCResultList)
                                    {
                                        if (IPCResultList.ContainsKey(IPCid))
                                        {
                                            IPCResultList[IPCid].resultCode = IPCResult;
                                            if (sLen > 0)
                                            {
                                                IPCResultList[IPCid].banReason = System.Text.ASCIIEncoding.ASCII.GetString(data, 11, sLen);
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine("[IPC] ResultList mismatch");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("[IPC] unknown command recevied");
                            }
                        }
                        else
                        {
                            Console.WriteLine("[IPC] data to short");
                        }
                    }
                    else
                    {
                        Console.WriteLine("[IPC] can't find the GameServer {0}:{1}", ((IPEndPoint)ep).Address.ToString(), pServer);
                    }
                }
                else
                {
                    Console.WriteLine("[IPC] packet to short from {0}", ep.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("[IPC.OnIPC] {0}", ex);
            }
        }