コード例 #1
0
        protected override void OnMessage(MessageEventArgs e)
        {
            try
            {
                switch (e.Type)
                {
                case Opcode.TEXT:
                {
                    JArray       dcode  = JArray.Parse(e.Data);
                    ClientOpcode opcode = (ClientOpcode)int.Parse(dcode[0].ToString());
                    LogConsole.Show(LogType.DEBUG, "opcode: {0}", opcode);
                    Program.PacketsManager.ProcessBytes(_session, ref dcode);
                    break;
                }

                default:
                {
                    break;
                }
                }
            }
            catch (Exception Ex)
            {
                LogConsole.Show(LogType.ERROR, "{0}", Ex.ToString());
            }
        }
コード例 #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)
            {
                LogConsole.Show("{0}", ex.Message);
            }

            return(retData);
        }
コード例 #3
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)
            {
                LogConsole.Show("{0}", ex.Message);
                return(false);
            }
        }
コード例 #4
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(LogType.INFO, "Successfully connected to {0}:{1}:{2}", host, port, database);
            }
            catch (MySqlException ex)
            {
                LogConsole.Show(LogType.ERROR, "{0}", ex.Message);

                // Try auto reconnect on error (every 5 seconds)
                LogConsole.Show(LogType.ALERT, "Try reconnect in 5 seconds...");
                Thread.Sleep(5000);

                Init(host, user, password, database, port);
            }
            catch (OverflowException exp)
            {
                LogConsole.Show(LogType.ERROR, "Error MYSQL: {0}", exp.ToString());
            }
        }
コード例 #5
0
        static void Main(string[] args)
        {
            LogConsole._Load();
            PATH = Environment.CurrentDirectory.ToString();
            Inix ini = null;

            #region Load Settings
            try
            {
                if (File.Exists(PATH + @"\Settings\Settings.ini"))
                {
                    ini    = new Inix(PATH + @"\Settings\Settings.ini");
                    LSPort = ini.GetValue("Server", "port", 9002).ToString();
                    LSIP   = ini.GetValue("Server", "ip", "localhost").ToString();

                    MIp   = ini.GetValue("MySql", "ip", "localhost").ToString();
                    MUser = ini.GetValue("MySql", "user", "root").ToString();
                    MPass = ini.GetValue("MySql", "pass", "").ToString();
                    MDb   = ini.GetValue("MySql", "db", "db_clone").ToString();
                    MPort = Convert.ToInt32(ini.GetValue("MySql", "port", 3306));

                    debug = Convert.ToBoolean(ini.GetValue("Console", "debug", false));

                    ini = null;
                    LogConsole.Show(LogType.INFO, "Has loaded your ip settings successfully");
                }
                else
                {
                    LogConsole.Show(LogType.ALERT, "Settings.ini could not be found, using default setting");
                }
            }
            catch (Exception excc)
            {
                LogConsole.Show(LogType.ERROR, " {0}", excc.ToString());
                return;
            }
            #endregion

            PacketsManager  = new Packets.PacketsManager();
            SessionsManager = new Components.SessionsManager();
            ChannelManager  = new ChannelManager();

            _SQL.Init(MIp, MUser, MPass, MDb, MPort);

            //MapsL.LoadMaps.Load();


            WSurl = WSurl + LSIP + ":" + LSPort;

            var wssv = new WebSocketServiceHost <Serverb>(WSurl);

            wssv.OnError += (sender, e) =>
            {
                LogConsole.Show(LogType.ERROR, "[WS]: Error {0} ", e.Message);
            };

            wssv.Start();
            LogConsole.Show(LogType.ALERT, "Server Listening on port: {0}", wssv.Port);

            _LoopThrreading          = new Thread(new ThreadStart(Program.LoopConsole));
            _LoopThrreading.Priority = ThreadPriority.BelowNormal;
            _LoopThrreading.Start();

            while (true)
            {
                Thread.Sleep(1000);

                string _comm = Console.ReadLine();
                switch (_comm)
                {
                case "online":
                    //LogConsole.Show(LogType.INFO, "Users Online: {0}", Users.Count());
                    break;

                default:
                    break;
                }
            }
        }
コード例 #6
0
        protected override void OnMessage(MessageEventArgs e)
        {
            try
            {
                switch (e.Type)
                {
                case Opcode.TEXT:
                {
                    JArray       dcode  = JArray.Parse(e.Data);
                    ClientOpcode opcode = (ClientOpcode)int.Parse(dcode[0].ToString());
                    LogConsole.Show(LogType.DEBUG, "opcode: {0}", opcode);
                    switch (opcode)
                    {
                    case ClientOpcode.login:
                    {
                        //[0,41,1,"123456789",1]
                        User.version  = dcode[1].ToObject <int>();
                        User.user_id  = dcode[2].ToObject <int>();
                        User.user_key = dcode[3].ToObject <string>();
                        User.Login();
                        LogConsole.Show(LogType.DEBUG, "User_Id: {0}", User.user_id);
                        Chat.ChatManager.Notice(User);
                        Chat.ChatManager.UpdateBoddy(this);
                        Channel.SendList();
                        User.ListFriends();
                        break;
                    }

                    case ClientOpcode.chat:
                    {
                        string chtm = dcode[1].ToString();
                        if (User.rank == 24)
                        {
                            string[] cd = chtm.Split(' ');
                            switch (cd[0])
                            {
                            case "/mobil":
                            {
                                Channel _cha = Program.Chanels.Single(a => a.UserIn(User) == true);
                                if (_cha != null)
                                {
                                    int _mobil = int.Parse(cd[1]);
                                    _cha.ChangeMobil(User, _mobil);
                                }
                                break;
                            }
                            }
                        }
                        Broadcast(Chat.ChatManager.Msj(chtm, User));
                        break;
                    }

                    case ClientOpcode.room_create:
                    {
                        //test script
                        Channel _new_c = new Channel();
                        _new_c.channel_id         = new Random().Next(2, 9);
                        _new_c.channel_name       = dcode[1].ToObject <string>();
                        _new_c.channel_password   = dcode[2].ToObject <string>();
                        _new_c.channel_maxplayers = dcode[3].ToObject <int>();
                        _new_c.channel_gamemode   = dcode[4].ToObject <int>();
                        User.Is_Master            = 1;
                        _new_c.Join(User);
                        Program.Chanels.Add(_new_c);
                        Channel.SendList();
                        break;
                    }

                    case ClientOpcode.room_join:
                    {
                        try
                        {
                            Channel _chan = Program.Chanels.Single(a => a.UserIn(User) == true);
                            if (_chan != null)
                            {
                                _chan.RemoveUser(User);
                            }
                        }
                        catch { }
                        int _sala_id = dcode[1].ToObject <int>();
                        try
                        {
                            Channel _cha = Program.Chanels.Single(a => a.channel_id == _sala_id);
                            if (_cha != null)
                            {
                                if (_cha.UserIn(User))
                                {
                                    _cha.RemoveUser(User);
                                }

                                _cha.Join(User);
                            }
                        }
                        catch { }
                        break;
                    }

                    case ClientOpcode.channel_join:
                    {
                        try
                        {
                            Channel _chan = Program.Chanels.Single(a => a.UserIn(User) == true);
                            if (_chan != null)
                            {
                                _chan.RemoveUser(User);
                            }
                        }
                        catch { }
                        User.PlayerInfo();
                        Chat.ChatManager.UpdateBoddy(this);
                        Channel.SendList();
                        break;
                    }

                    case ClientOpcode.mobile:
                    {
                        Channel _cha = Program.Chanels.Single(a => a.UserIn(User) == true);
                        if (_cha != null)
                        {
                            int _mobil = dcode[1].ToObject <int>();
                            _cha.ChangeMobil(User, _mobil);
                        }
                        break;
                    }

                    case ClientOpcode.get_my_avatars:
                    {
                        User.GetAvatars();
                        break;
                    }

                    case ClientOpcode.equip:
                    {
                        User.SendEquip(dcode[1].ToString());
                        break;
                    }

                    case ClientOpcode.buy:
                    {
                        User.BuyItems(dcode[1].ToObject <string>(), dcode[2].ToObject <string>(), dcode[3].ToObject <int>(), dcode[4].ToObject <int>());
                        break;
                    }

                    case ClientOpcode.change_name:
                    {
                        User.ChangeName(dcode[1].ToObject <string>());
                        User.PlayerInfo();
                        Chat.ChatManager.UpdateBoddy(this);
                        break;
                    }

                    case ClientOpcode.tab:
                    {
                        int idt = dcode[1].ToObject <int>();
                        switch (idt)
                        {
                        case 0:
                        {
                            Chat.ChatManager.UpdateBoddy(this);
                            break;
                        }

                        case 2:
                        {
                            //User.sep.Send("[19]");
                            User.Guildinfo();
                            break;
                        }
                        }
                        break;
                    }

                    case ClientOpcode.guild_create:
                    {
                        string guild_name = dcode[1].ToObject <string>();
                        LogConsole.Show(LogType.DEBUG, "GuildC: {0}", guild_name);
                        break;
                    }

                    case ClientOpcode.refresh_friends:
                    {
                        User.ListFriends();
                        break;
                    }

                    case ClientOpcode.refresh_guildies:
                    {
                        User.Guildinfo();
                        break;
                    }

                    case ClientOpcode.room_change_ready:
                    {
                        Channel _chan = Program.Chanels.Single(a => a.UserIn(User) == true);
                        if (_chan != null)
                        {
                            _chan.ChangeReady(User, dcode[1].ToObject <int>());
                        }
                        break;
                    }

                    case ClientOpcode.game_start:
                    {
                        Channel _chan = Program.Chanels.Single(a => a.UserIn(User) == true);
                        if (_chan != null)
                        {
                            _chan.GameStart();
                        }
                        break;
                    }

                    case ClientOpcode.game_move:
                    {
                        Channel _chan = Program.Chanels.Single(a => a.UserIn(User) == true);
                        if (_chan != null)
                        {
                            User.x         = dcode[1].ToObject <int>();
                            User.y         = dcode[2].ToObject <int>();
                            User.body_move = dcode[3].ToObject <int>();
                            User.look      = dcode[4].ToObject <int>();
                            User.ang       = dcode[5].ToObject <int>();
                            _chan.Move(User);
                        }
                        break;
                    }

                    case ClientOpcode.game_shoot:
                    {
                        Channel _chan = Program.Chanels.Single(a => a.UserIn(User) == true);
                        if (_chan != null)
                        {
                            _chan.GameShoot(User, dcode[1].ToObject <int>(), dcode[2].ToObject <int>(), dcode[3].ToObject <int>(), dcode[4].ToObject <int>(), dcode[5].ToObject <int>(), dcode[6].ToObject <int>(), dcode[7].ToObject <int>(), dcode[8].ToObject <int>());
                        }
                        break;
                    }

                    case ClientOpcode.game_pass_turn:
                    {
                        //[14,1585,98,-18,0,24,6]
                        //[28,[4,0,1585,98,0,585,1,[],652,-436,18,0,2,0,99]]
                        Channel _chan = Program.Chanels.Single(a => a.UserIn(User) == true);
                        if (_chan != null)
                        {
                            int _uid  = dcode[1].ToObject <int>();
                            int _x    = dcode[2].ToObject <int>();
                            int _y    = dcode[3].ToObject <int>();
                            int _body = dcode[4].ToObject <int>();
                            int _look = dcode[5].ToObject <int>();
                            int _angl = dcode[6].ToObject <int>();
                            int _time = dcode[7].ToObject <int>();
                        }
                        break;
                    }

                    case ClientOpcode.room_change_team:
                    {
                        Channel _chan = Program.Chanels.Single(a => a.UserIn(User) == true);
                        if (_chan != null)
                        {
                            _chan.ChangeTeam(User, dcode[1].ToObject <string>());
                        }
                        break;
                    }

                    case ClientOpcode.select_bot:
                    {
                        //[22,1,"0"] slot - id_bot
                        //[35,[2,1,[],1,131702018,"Clown Stripe",0,0,0,1,"m",0,[17,31],1,0]]
                        Channel _chan = Program.Chanels.Single(a => a.UserIn(User) == true);
                        if (_chan != null)
                        {
                            _chan.AddBot(dcode[1].ToObject <int>(), dcode[1].ToObject <string>());
                        }
                        break;
                    }

                    default:
                    {
                        Console.WriteLine("opcode: {0}", opcode);
                        Console.WriteLine("data: {0}", e.Data);
                        break;
                    }
                    }
                    break;
                }

                default:
                {
                    Console.WriteLine("tp: {0}", e.Type);
                    break;
                }
                }
            }
            catch (Exception Ex)
            {
                LogConsole.Show(LogType.ERROR, "{0}", Ex.ToString());
            }
        }