示例#1
0
        public void Init(string host, string user, string password, string database, int port)
        {
            Connection = new MySqlConnection("Server=" + host + ";User Id=" + user + ";Port=" + port + ";" +
                                             "Password="******";Database=" + database + ";Allow Zero Datetime=True");

            try
            {
                Connection.Open();
                LogConsole.Show("MYSQL Connected to Host: [{0}] at Port: [{1}] using DB: [{2}]", host, port, database);
            }
            catch (MySqlException ex)
            {
                LogDebug.Show("{0}", ex.Message);

                // Try auto reconnect on error (every 5 seconds)
                LogDebug.Show("Try reconnect in 5 seconds...");
                Thread.Sleep(5000);

                Init(host, user, password, database, port);
            }
            catch (OverflowException exp)
            {
                LogDebug.Show("Error MYSQL: {0}", exp.ToString());
            }
        }
示例#2
0
        public static void OPCode(Decode decode)
        {
            try
            {
                Systems sys = (Systems)decode.Packet;
                sys.PacketInformation = decode;
                PacketReader Reader = new PacketReader(sys.PacketInformation.buffer);
                LogDebug.Show("Opcode: {0}", decode.opcode);
                Opcode opc = (Opcode)decode.opcode;
                switch (opc)
                {
                case Opcode._MSG_LOGIN:
                {
                    string username_shift = Reader.String(32);
                    string password_md5   = Reader.String(32);
                    Reader.Skip(4);
                    string client_mac = Reader.String(32);
                    Reader.Skip(32);
                    uint        unk3     = Reader.UInt32();
                    StringShift shift    = new StringShift();
                    string      username = shift.Parser(username_shift);
                    LogDebug.Show("username: {0}", username);
                    LogDebug.Show("password_md5: {0}", password_md5);
                    LogDebug.Show("Mac: {0}", client_mac);
                    LogDebug.Show("unk3: {0}", unk3);
                    int res = UserLogin(username, password_md5, client_mac);
                    if (res == (int)AuthenticationStatus.OK)
                    {
                        sys.client.SendC(NewCharacterPacket());
                    }
                    else if (res == (int)AuthenticationStatus.BANNED)
                    {
                        sys.client.SendC(UserFail(0xF0, Reason.BANNED));
                    }
                    else
                    {
                        sys.client.SendC(UserFail(0xF0, Reason.AUTH_FAILED));
                    }
                }
                break;

                default:
                    LogConsole.Show("Default Opcode: {0:X} - {1}", decode.opcode, opc);
                    LogDebug.HexDump(sys.PacketInformation.buffer, 16, true, false);
                    break;
                }
            }
            catch (Exception)
            {
            }
        }
示例#3
0
            public void ReceiveData(IAsyncResult ar)
            {
                Socket wSocket = (Socket)ar.AsyncState;

                try
                {
                    if (wSocket.Connected)
                    {
                        int  recvSize  = wSocket.EndReceive(ar); // get the count of received bytes
                        bool checkData = true;
                        if (recvSize > 0)
                        {
                            if ((recvSize + bufCount) > MAX_BUFFER)  // that may be a try to force buffer overflow, we don't allow that ;)
                            {
                                checkData = false;
                                LocalDisconnect(wSocket);
                            }
                            else
                            {                                                            // we have something in input buffer and it is not beyond our limits
                                Buffer.BlockCopy(tmpbuf, 0, buffer, bufCount, recvSize); // copy the new data to our buffer
                                bufCount += recvSize;                                    // increase our buffer-counter
                            }
                        }
                        else
                        {   // 0 bytes received, this should be a disconnect
                            checkData = false;
                            LocalDisconnect(wSocket);
                        }

                        while (checkData) // repeat while we have data
                        {
                            checkData = false;
                            if (bufCount >= 4) // a minimum of 4 byte is required for us
                            {
                                byte[] _newtmp = new byte[bufCount];
                                Buffer.BlockCopy(buffer, 0, _newtmp, 0, bufCount);
                                LogDebug.HexDump(_newtmp, 16, true, true);
                                Decode de = new Decode(buffer);                                         // only get the size first.
                                LogConsole.Show("bufCount: {0} dataSize: {1}", bufCount, de.dataSize);
                                if (bufCount >= (de.dataSize - 2))                                      // It's a complete packet. Call the handler.
                                {
                                    de = new Decode(wSocket, de.tempbuff, this, Packets);               // build up the Decode structure for next step
                                    OnReceiveData(de);                                                  // call the handling routine
                                    bufCount -= (de.dataSize);                                          // decrease buffer-counter
                                    if (bufCount >= 0)                                                  // was the buffer greater than what the packet needs? then it may be the next packet.
                                    {
                                        Buffer.BlockCopy(buffer, 2 + de.dataSize, buffer, 0, bufCount); // move the rest to buffer start
                                        checkData = true;                                               // loop for next packet
                                    }
                                }
                                else
                                {
                                    byte[] _tempddd = new byte[bufCount];
                                    EncDec end      = new EncDec();
                                    byte[] dddxx    = end.Crypt(buffer);
                                    Buffer.BlockCopy(dddxx, 0, _tempddd, 0, de.dataSize);
                                    LogConsole.Show("bufCount: {0} dataSize: {1}", bufCount, de.dataSize);
                                }
                                de = null;
                            }
                        }
                        // start the next async read
                        if (wSocket != null && wSocket.Connected)
                        {
                            wSocket.BeginReceive(tmpbuf, 0, tmpbuf.Length, SocketFlags.None, new AsyncCallback(ReceiveData), wSocket);
                        }
                    }
                    else
                    {
                        LocalDisconnect(wSocket);
                    }
                }
                catch (SocketException)  // explicit handling of SocketException
                {
                    LocalDisconnect(wSocket);
                }
                catch (Exception) // other exceptions
                {
                    LocalDisconnect(wSocket);
                }
            }
示例#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);
     }
 }
示例#5
0
        static void Main(string[] args)
        {
            Program pro = new Program();

            GameServer.Definitions.Bootlogo._Load();
            Systems.Ini ini = null;
            LogConsole.Init();

            #region Default Settings
            int    LSPort  = 7000;
            int    IPCPort = 7000;
            string LSIP    = "127.0.0.1";
            string IPCIP   = "127.0.0.1";
            #endregion

            #region Load Settings
            try
            {
                if (File.Exists(Environment.CurrentDirectory + @"\Settings\GS-Settings.ini"))
                {
                    ini        = new Systems.Ini(Environment.CurrentDirectory + @"\Settings\GS-Settings.ini");
                    LSPort     = Convert.ToInt32(ini.GetValue("GAMESERVER", "port", 7000));
                    LSIP       = ini.GetValue("SERVER", "ip", "127.0.0.1").ToString();
                    IPCPort    = Convert.ToInt32(ini.GetValue("IPC", "port", 7000));
                    IPCIP      = ini.GetValue("IPC", "ip", "127.0.0.1").ToString();
                    debug      = ini.GetValue("CONSOLE", "debug", false);
                    MYSQL_USER = ini.GetValue("MYSQL", "user", "root");
                    MYSQL_PASS = ini.GetValue("MYSQL", "pass", "123456");
                    MYSQL_DATA = ini.GetValue("MYSQL", "data", "godswar");
                    MYSQL_IP   = ini.GetValue("MYSQL", "ip", "127.0.0.1");
                    MYSQL_PORT = ini.GetValue("MYSQL", "port", 3306);
                    ini        = null;
                    LogConsole.Show("MYSQL Connection Server-Settings... LOADED!");
                }
                else
                {
                    LogConsole.Show("Server-Settings.ini could not be found, doing fallback to default settings!");
                }
            }
            catch (Exception)
            {
                return;
            }
            #endregion

            _SQL.Init(MYSQL_IP, MYSQL_USER, MYSQL_PASS, MYSQL_DATA, MYSQL_PORT);

            Systems.Server net = new Systems.Server();

            net.OnConnect += new Systems.Server.dConnect(pro._OnClientConnect);
            net.OnError   += new Systems.Server.dError(pro._ServerError);

            Systems.Client.OnReceiveData += new Systems.Client.dReceive(pro._OnReceiveData);
            Systems.Client.OnDisconnect  += new Systems.Client.dDisconnect(pro._OnClientDisconnect);

            try
            {
                net.Start(LSIP, LSPort);
            }
            catch (Exception ex)
            {
                LogConsole.Show("Error Initializing Server: {0}", ex);
            }

            #region Load GameServers
            //Systems.LoadServers("GameServers.ini", 6001);
            #endregion

            #region IPC Listener

            /*IPCServer = new Network.Servers.IPCServer();
             * IPCServer.OnReceive += new Network.Servers.IPCServer.dOnReceive(pro.OnIPC);
             * try
             * {
             *  IPCServer.Start(IPCIP, IPCPort);
             *  foreach (KeyValuePair<int, Systems.SRX_Serverinfo> Server in Systems.GSList)
             *  {
             *      byte[] rqPacket = IPCServer.PacketRequestServerInfo(IPCPort);
             *      Network.Servers.IPCenCode(ref rqPacket, Server.Value.code);
             *      IPCServer.Send(Server.Value.ip, Server.Value.ipcport, rqPacket);
             *      rqPacket = null;
             *  }
             * }
             * catch (Exception ex)
             * {
             *  LogConsole.Show("Error start ICP: {0}", ex);
             * }*/
            #endregion

            //LogConsole.Show("Ready for gameserver connection...");
            #region Loop Update GameServers
            while (true)
            {
                Thread.Sleep(100);

                /*foreach (KeyValuePair<int, Systems.SRX_Serverinfo> SSI in Systems.GSList)
                 * {
                 *  if (SSI.Value.status != 0 && SSI.Value.lastPing.AddMinutes(5) < DateTime.Now) // server unavailable
                 *  {
                 *      SSI.Value.status = 0;
                 *      LogConsole.Show("Server: {0}:({1}) has timed out, status changed to check", SSI.Value.id, SSI.Value.name);
                 *  }
                 * }*/
            }
            #endregion
        }
示例#6
0
 public void _OnClientConnect(ref object de, Systems.Client net)
 {
     LogConsole.Show("New Client Connection Received!");
     de = new Systems(net);
 }