Ejemplo n.º 1
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 + "");
            }
        }
Ejemplo n.º 2
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);
            }
        }