Esempio n. 1
0
        public static Systems.SRX_Serverinfo Getserverbyname(string name)
        {
            Systems.SRX_Serverinfo GS = null;

            foreach (KeyValuePair <int, Systems.SRX_Serverinfo> GSI in Systems.GSList)
            {
                if (GSI.Value.name == name)
                {
                    GS = GSI.Value;
                }
            }
            return(GS);
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (srvList.SelectedItem == null)
     {
         MessageBox.Show("You must select a server to edit!", "[SRX]", MessageBoxButtons.OK);
     }
     else
     {
         Systems.SRX_Serverinfo information = Getserverbyname(srvList.SelectedItem.ToString());
         serverIP.Text   = information.ip;
         serverName.Text = information.name;
         serverPort.Text = information.port.ToString();
         protCode.Text   = information.code;
         //Add db by command console from gs
     }
 }
Esempio n. 4
0
 public static int LoadServers(string serverFile, UInt16 defaultPort)
 {
     try
     {
         if (File.Exists(Environment.CurrentDirectory + @"\Settings\" + serverFile))
         {
             Systems.Ini ini = new Systems.Ini(Environment.CurrentDirectory + @"\Settings\" + serverFile);
             string[] sList = null;
             sList = ini.GetEntryNames("SERVERS");
             if (sList!=null && sList.Length > 0)
             {
                 foreach (string sectname in sList)
                 {
                     string sName = ini.GetValue("SERVERS", sectname, "");
                     Systems.SRX_Serverinfo SServerInfo = new Systems.SRX_Serverinfo();
                     SServerInfo.id = Convert.ToUInt16(ini.GetValue(sName, "id", 0));
                     SServerInfo.ip = ini.GetValue(sName, "ip", "192.168.1.5");
                     SServerInfo.wan = ini.GetValue(sName, "wan", "192.168.1.5");
                     SServerInfo.name = ini.GetValue(sName, "name", sName);
                     SServerInfo.port = Convert.ToUInt16(ini.GetValue(sName, "port", defaultPort));
                     SServerInfo.ipcport = Convert.ToUInt16(ini.GetValue(sName, "ipcport", "6001"));
                     SServerInfo.code = ini.GetValue(sName, "code", "");
                     SServerInfo.lan_wan = ini.GetValue(sName, "lan_wan", "0") == "1" ? true : false;
                     SServerInfo.Version = Convert.ToInt32(ini.GetValue(sName, "version", 0));
                     if (SServerInfo.ip == "" || SServerInfo.port == 0 || SServerInfo.id == 0 || SServerInfo.ipcport == 0 || GSList.ContainsKey(SServerInfo.id))
                     {
                         LogDebug.Show("IPC: Error on Server " + sName + " in " + serverFile + ": field missing or id already in use!");
                         SServerInfo = null;
                     }
                     else
                     {
                         GSList.Add(SServerInfo.id, SServerInfo);
                     }
                 }
             }
             if (GSList.Count() > 0)
             {
                 string servers = "Server";
                 if (GSList.Count > 1) servers = "Servers";
                 LogConsole.Show("Loaded " + GSList.Count() + " " + servers + " from server settings");
             }
             else
             {
                 Systems.SRX_Serverinfo GServer = new Systems.SRX_Serverinfo();
                 GServer.id = 1;
                 GServer.ip = "192.168.1.5";
                 if (Global.Network.multihomed)
                 {
                     //Multihomed
                 }
                 else
                 {
                     GServer.extip = Global.Network.LocalIP;
                 }
                 GServer.name = "[SERVER] Default";
                 GServer.port = defaultPort;
                 GServer.ipcport = 6001;
                 GServer.code = "xdxdxdxdxdxd";
                 GSList.Add(GServer.id, GServer);
             }
             sList = null;
             ini = null;
             return GSList.Count();
         }
         else
         {
             Systems.SRX_Serverinfo GServer = new Systems.SRX_Serverinfo();
             GServer.id = 1;
             GServer.ip = "192.168.1.5";
             if (Global.Network.multihomed)
             {
                 //Multihomed
             }
             else
             {
                 //No servers
                 GServer.extip = Global.Network.LocalIP;
             }
             GServer.name = "[SERVER "+ Global.Versions.appVersion +"]";
             GServer.port = defaultPort;
             GServer.ipcport = 6001;
             GServer.code = "";
             GSList.Add(GServer.id, GServer);
             return -1;
         }
     }
     catch (Exception ex)
     {
         LogConsole.Show("Error loading GameServer settings " + ex + "");
         return -2;
     }
 }
Esempio n. 5
0
 public static int LoadServers(string serverFile, UInt16 defaultPort)
 {
     try
     {
         if (File.Exists(Environment.CurrentDirectory + @"\Settings\" + serverFile))
         {
             Systems.Ini ini   = new Systems.Ini(Environment.CurrentDirectory + @"\Settings\" + serverFile);
             string[]    sList = null;
             sList = ini.GetEntryNames("SERVERS");
             if (sList != null && sList.Length > 0)
             {
                 foreach (string sectname in sList)
                 {
                     string sName = ini.GetValue("SERVERS", sectname, "");
                     Systems.SRX_Serverinfo SServerInfo = new Systems.SRX_Serverinfo();
                     SServerInfo.id      = Convert.ToUInt16(ini.GetValue(sName, "id", 0));
                     SServerInfo.ip      = ini.GetValue(sName, "ip", "192.168.1.5");
                     SServerInfo.wan     = ini.GetValue(sName, "wan", "192.168.1.5");
                     SServerInfo.name    = ini.GetValue(sName, "name", sName);
                     SServerInfo.port    = Convert.ToUInt16(ini.GetValue(sName, "port", defaultPort));
                     SServerInfo.ipcport = Convert.ToUInt16(ini.GetValue(sName, "ipcport", "6001"));
                     SServerInfo.code    = ini.GetValue(sName, "code", "");
                     SServerInfo.lan_wan = ini.GetValue(sName, "lan_wan", "0") == "1" ? true : false;
                     SServerInfo.Version = Convert.ToInt32(ini.GetValue(sName, "version", 0));
                     if (SServerInfo.ip == "" || SServerInfo.port == 0 || SServerInfo.id == 0 || SServerInfo.ipcport == 0 || GSList.ContainsKey(SServerInfo.id))
                     {
                         LogDebug.Show("IPC: Error on Server " + sName + " in " + serverFile + ": field missing or id already in use!");
                         SServerInfo = null;
                     }
                     else
                     {
                         GSList.Add(SServerInfo.id, SServerInfo);
                     }
                 }
             }
             if (GSList.Count() > 0)
             {
                 string servers = "Server";
                 if (GSList.Count > 1)
                 {
                     servers = "Servers";
                 }
                 LogConsole.Show("Loaded " + GSList.Count() + " " + servers + " from server settings");
             }
             else
             {
                 Systems.SRX_Serverinfo GServer = new Systems.SRX_Serverinfo();
                 GServer.id = 1;
                 GServer.ip = "192.168.1.5";
                 if (Global.Network.multihomed)
                 {
                     //Multihomed
                 }
                 else
                 {
                     GServer.extip = Global.Network.LocalIP;
                 }
                 GServer.name    = "[SERVER] Default";
                 GServer.port    = defaultPort;
                 GServer.ipcport = 6001;
                 GServer.code    = "xdxdxdxdxdxd";
                 GSList.Add(GServer.id, GServer);
             }
             sList = null;
             ini   = null;
             return(GSList.Count());
         }
         else
         {
             Systems.SRX_Serverinfo GServer = new Systems.SRX_Serverinfo();
             GServer.id = 1;
             GServer.ip = "192.168.1.5";
             if (Global.Network.multihomed)
             {
                 //Multihomed
             }
             else
             {
                 //No servers
                 GServer.extip = Global.Network.LocalIP;
             }
             GServer.name    = "[SERVER " + Global.Versions.appVersion + "]";
             GServer.port    = defaultPort;
             GServer.ipcport = 6001;
             GServer.code    = "";
             GSList.Add(GServer.id, GServer);
             return(-1);
         }
     }
     catch (Exception ex)
     {
         LogConsole.Show("Error loading GameServer settings " + ex + "");
         return(-2);
     }
 }
Esempio n. 6
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 + "");
            }
        }
Esempio n. 7
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);
            }
        }