예제 #1
0
        public Player LoadPlayer(int id)
        {
            SqliteCommand cmd;

            try
            {
                cmd = connection.CreateCommand();
            }
            catch (Exception)
            {
                return(null);
            }

            cmd.CommandText = "SELECT * FROM players WHERE ids = " + id;
            SqliteDataReader data = cmd.ExecuteReader();

            object[] objs = new object[data.FieldCount];
            int      i    = 0;

            data.Read();
            while (i < data.FieldCount)
            {
                objs[i] = data.GetValue(i);
                i++;
            }
            Player player = new Player();

            //ID //FINISH
            try
            {
                player.id           = int.Parse(objs[0].ToString());
                player.name         = objs[1].ToString();
                player.level        = int.Parse(objs[2].ToString());//Subway
                player.attacklevel  = int.Parse(objs[3].ToString());
                player.attackxp     = int.Parse(objs[4].ToString());
                player.defencelevel = int.Parse(objs[5].ToString());
                player.defencexp    = int.Parse(objs[6].ToString());
                player.magiclevel   = int.Parse(objs[7].ToString());
                player.magicxp      = int.Parse(objs[8].ToString());
                player.kills        = int.Parse(objs[9].ToString());
                player.health       = int.Parse(objs[10].ToString());
                player.admin        = MiscMethods.IntToBool(int.Parse(objs[11].ToString()));
                player.banned       = MiscMethods.IntToBool(int.Parse(objs[12].ToString()));
                return(player);
            }
            catch (Exception crap)
            {
                Logger.LogMsg("Loading player failed", 1);
                Logger.LogMsg("Reason: " + crap.Message, 2);
                return(null);
            }
        }
예제 #2
0
 public override string ToString()
 {
     return(id + ","                             //0
            + name + ","                         //1
            + maxhealth + ","                    //2
            + health + ","                       //3
            + attackxp + ","                     //4
            + defencexp + ","                    //5
            + magicxp + ","                      //6
            + kills + ","                        //7
            + position.ToString() + ","          //8 //9 //10
            + attacklevel + ","                  //11
            + defencelevel + ","                 //12
            + magiclevel + ","                   //13
            + level + ","                        //14
            + MiscMethods.BoolToInt(admin) + "," //15
            + MiscMethods.BoolToInt(banned));    //16
 }
예제 #3
0
        public bool CreateAccount(string name, string password, int id)
        {
            if (id < 0)
            {
                return(false);                //Invalid id.
            }
            SqliteCommand cmd    = connection.CreateCommand();
            int           output = 0;

            try {
                cmd.CommandText = "INSERT INTO accounts VALUES('" + name + "','" + password + "'," + id + ")";
                output          = cmd.ExecuteNonQuery();
                Logger.LogMsg("SQL>Creating Account '" + name + "' returned " + output, 2);
            } catch (SqliteException ex) {
                Logger.LogMsg("SQL>Creating Account failed, Exception " + ex.Message, 2);
            }
            return(MiscMethods.IntToBool(output));
        }
예제 #4
0
        public static void DeterminePacket(string msg, WebSocketSession uc)
        {
            //[TPE]
            string determiner = msg.Substring(1, 3);
            string arguments  = msg.Substring(5, msg.Length - 5);

            string[] argarray = arguments.Split(',');
            Player   plr      = Program.server.GetPlayerByIP(uc.RemoteEndPoint.Address + ":" + uc.RemoteEndPoint.Port);

            switch (determiner)
            {
            case "RET":
                Logger.LogMsg("Ping Returned.", 3);
                break;

            case "REQ":
                Logger.LogMsg("Ping Requested", 3);
                uc.Send("[RET]PING!!!");
                break;

            case "LOD":
                Logger.LogMsg("Load User Request.", 3);
                Player newplayer = Program.database.LoadPlayer(int.Parse(arguments));
                newplayer.session = uc;
                newplayer.address = uc.RemoteEndPoint.Address.ToString() + ":" + uc.RemoteEndPoint.Port;
                uc.Send("[LOD]" + newplayer.ToString());
                Program.server.MainGame.entityHandler.AddEnt(newplayer);
                if (newplayer.banned)
                {
                    Program.server.KickPlayer(newplayer, "Your Banned");
                }
                break;

            case "CMD":
                Logger.LogMsg("Command recieved : " + arguments, 3);
                Program.server.ParseClientCommand(arguments, uc);
                break;

            case "ACN":
                Logger.LogMsg("User requires account details, checking authentication.", 3);
                int response = Program.database.Authenticate(arguments.Split(','));
                switch (response)
                {
                case -1:
                    uc.Send("[ACN]002");                      //NotFound
                    break;

                case -2:
                    uc.Send("[ACN]002");                      //NotFound
                    break;

                case -3:
                    uc.Send("[ACN]003");                      //PasswordWrong
                    break;

                default:
                    uc.Send("[ACN]" + response);                      //Retrieved ok
                    break;
                }
                break;

            case "NEW":
                Logger.LogMsg("New user request.");
                //Usr,Pwd,Acc
                string problems = "";
                if (argarray [0] == "" || argarray [0].Length > 16)
                {
                    problems += "2";
                }

                if (argarray [1] == "" || argarray [1].Length > 16)
                {
                    if (problems.Length > 0)
                    {
                        problems += ",";
                    }
                    problems += "3";
                }

                if (argarray [2] == "" || argarray [2].Length > 16)
                {
                    if (problems.Length > 0)
                    {
                        problems += ",";
                    }
                    problems += "4";
                }
                if (Program.database.DoesAccountExist(argarray [0]))
                {
                    if (problems.Length > 0)
                    {
                        problems += ",";
                    }
                    problems += "1";
                }
                if (string.IsNullOrWhiteSpace(problems))
                {
                    bool worked = Program.database.AddPlayer(argarray [2], 0);
                    int  id     = Program.database.GetPlayerID(argarray [2]);
                    if (id == -1)
                    {
                        worked = false;
                    }
                    if (worked)
                    {
                        worked = Program.database.CreateAccount(argarray [0], argarray [1], id);
                    }

                    if (worked)
                    {
                        Logger.LogMsg("Account created", 3);
                        uc.Send("[NEW]0");
                    }
                    else
                    {
                        Logger.LogMsg("Account creation failed. Database problems.", 3);
                        uc.Send("[NEW]5");
                    }
                }
                else
                {
                    Logger.LogMsg("Account couldn't be created due to reasons " + problems, 3);
                    uc.Send("[NEW]" + problems);
                }
                break;

            case "MAP":
                //Request for map data.
                string mapdata = MiscMethods.StringArrayToString(Program.server.MainGame.map.ToStringArray());
                uc.Send("[MAP]" + mapdata);
                break;

            case "RDY":
                //All data recieved, client is ready
                if (plr != null)
                {
                    plr.waitingToSpawn = true;
                }
                break;

            default:
                break;
            }
        }