Example #1
0
        public bool Execute(string sql, params object[] args)
        {
            StringBuilder sqlString = new StringBuilder();

            // Fix for floating point problems on some languages
            sqlString.AppendFormat(CultureInfo.GetCultureInfo("en-US").NumberFormat, sql);

            MySqlCommand sqlCommand = new MySqlCommand(sqlString.ToString(), Connection);

            try
            {
                List <MySqlParameter> mParams = new List <MySqlParameter>(args.Length);

                foreach (var a in args)
                {
                    mParams.Add(new MySqlParameter("", a));
                }

                sqlCommand.Parameters.AddRange(mParams.ToArray());
                sqlCommand.ExecuteNonQuery();
                return(true);
            }
            catch (MySqlException ex)
            {
                LogDebug.Show("{0}", ex.Message);
                return(false);
            }
        }
Example #2
0
        public SQLResult Select(string sql, params object[] args)
        {
            SQLResult retData = new SQLResult();

            StringBuilder sqlString = new StringBuilder();

            // Fix for floating point problems on some languages
            sqlString.AppendFormat(CultureInfo.GetCultureInfo("en-US").NumberFormat, sql);

            MySqlCommand sqlCommand = new MySqlCommand(sqlString.ToString(), Connection);

            try
            {
                List <MySqlParameter> mParams = new List <MySqlParameter>(args.Length);

                foreach (var a in args)
                {
                    mParams.Add(new MySqlParameter("", a));
                }

                sqlCommand.Parameters.AddRange(mParams.ToArray());
                SqlData = sqlCommand.ExecuteReader(CommandBehavior.Default);
                retData.Load(SqlData);
                retData.Count = retData.Rows.Count;
                SqlData.Close();
            }
            catch (MySqlException ex)
            {
                LogDebug.Show("{0}", ex.Message);
            }

            return(retData);
        }
Example #3
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());
            }
        }
Example #4
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)
            {
            }
        }
Example #5
0
        public void OnIPC(System.Net.Sockets.Socket aSocket, System.Net.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);
            }
        }
Example #6
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);
                }
            }
 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);
     }
 }
Example #8
0
 private void _ServerError(Exception ex)
 {
     LogDebug.Show(ex.ToString());
 }