Ejemplo n.º 1
0
    public async Task <int> Flush()
    {
        List <MySqlParameter> countParams = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?id", iid)
        };
        DataTable rows = await Server.DB.QueryAsync("SELECT COUNT(*) as count FROM [[player]].item WHERE `id`=?id LIMIT 1", countParams);

        Int32.TryParse(rows.Rows[0]["count"].ToString(), out int rCount);
        if (rCount == 0)
        {
            Logger.Syserr("Attempted to flush an item that didn't already exist in the database!");
        }
        else
        {
            List <MySqlParameter> dumpParams = new List <MySqlParameter>()
            {
                MySQL_Param.Parameter("?id", iid),
                MySQL_Param.Parameter("?vnum", data.vnum),
                MySQL_Param.Parameter("?owner", ownerPid),
                MySQL_Param.Parameter("?window", window.ToString()),
                MySQL_Param.Parameter("?count", count),
                MySQL_Param.Parameter("?pos", position),
            };
            await Server.DB.QueryAsync("UPDATE [[player]].item SET `owner`=?owner, `window`=?window, `count`=?count, `pos`=?pos WHERE `id`=?id AND `vnum`=?vnum LIMIT 1", dumpParams);

            return(0);
        }
        return(1);
    }
Ejemplo n.º 2
0
    public static async Task <bool> AccountOwnsPlayer(int cid, int pid)
    {
        AuthCore core = (AuthCore)Server.the_core;
        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?id", pid),
        };
        DataTable result = await Server.DB.QueryAsync("SELECT * FROM [[player]].player WHERE `id`=?id LIMIT 1", _params);

        if (result.Rows.Count == 0)
        {
            return(false);
        }

        Int32.TryParse(result.Rows[0]["aid"].ToString(), out int aid);
        Int32.TryParse(result.Rows[0]["id"].ToString(), out int _pid);
        if (aid <= 0 || _pid < 0)
        {
            return(false);
        }

        if (core.Clients[cid].aid != aid)
        {
            return(false);
        }

        return(true);
    }
Ejemplo n.º 3
0
    public static async void SendDisconnectPacketToAlreadyConnectedClient(int client)
    {
        AuthCore core     = (AuthCore)Server.the_core;
        bool     isOnline = false;

        foreach (KeyValuePair <int, AuthClient> cc in core.Clients)
        {
            if (cc.Value.tcp != null && cc.Value != core.Clients[client])
            {
                if (cc.Value.tcp.socket != null)
                {
                    if (cc.Value.tcp.socket.Connected)
                    {
                        isOnline = true;
                        // send a disconnect packet

                        break;
                    }
                }
            }
        }

        if (!isOnline)
        {
            List <MySqlParameter> delSess = new List <MySqlParameter>()
            {
                MySQL_Param.Parameter("?id", core.Clients[client].aid),
            };
            await Server.DB.QueryAsync("DELETE FROM [[player]].sessions WHERE `aid`=?id LIMIT 1", delSess);
        }
    }
Ejemplo n.º 4
0
    public static async Task <DataTable> GetPlayerData(int pid)
    {
        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?id", pid),
        };
        DataTable result = await Server.DB.QueryAsync("SELECT * FROM [[player]].player WHERE `id`=?id LIMIT 1", _params);

        return(result);
    }
Ejemplo n.º 5
0
 public static async void CreateSessionInDatabase(int client, int aid)
 {
     AuthCore core = (AuthCore)Server.the_core;
     List <MySqlParameter> sessParams = new List <MySqlParameter>()
     {
         MySQL_Param.Parameter("?session", core.Clients[client].session_id),
         MySQL_Param.Parameter("?pid", core.Clients[client].session_id),             // as a temporary pid
         MySQL_Param.Parameter("?aid", aid)
     };
     await Server.DB.QueryAsync("INSERT INTO [[player]].sessions (session,pid,aid) VALUES (?session,?pid,?aid)", sessParams);
 }
Ejemplo n.º 6
0
    public static async Task <int> AssignPidToSession(DataTable rows, int cid)
    {
        AuthCore core = (AuthCore)Server.the_core;
        List <MySqlParameter> sParams = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?session", core.Clients[cid].session_id),
            MySQL_Param.Parameter("?pid", rows.Rows[0]["id"].ToString()),
            MySQL_Param.Parameter("?aid", rows.Rows[0]["aid"].ToString())
        };
        await Server.DB.QueryAsync("UPDATE [[player]].sessions SET `pid`=?pid WHERE `session`=?session AND `aid`=?aid LIMIT 1", sParams);

        return(1);
    }
Ejemplo n.º 7
0
    private async void createItemInDb()
    {
        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?vnum", this.data.vnum),
            MySQL_Param.Parameter("?owner", this.ownerPid),
            MySQL_Param.Parameter("?window", this.window.ToString()),
            MySQL_Param.Parameter("?count", this.count),
            MySQL_Param.Parameter("?pos", this.position)
        };

        this.iid = await Server.DB.QuerySyncReturnAIAsync("INSERT INTO [[player]].item (`vnum`,`owner`,`window`,`count`,`pos`) VALUES (?vnum,?owner,?window,?count,?pos)", _params);
    }
Ejemplo n.º 8
0
    public static async Task <bool> isGM(int pid)
    {
        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?pid", pid),
        };
        DataTable result = await Server.DB.QueryAsync("SELECT COUNT(*) as count FROM [[player]].PLAYER WHERE `id`=?pid LIMIT 1", _params);

        if (result.Rows[0]["count"].ToString() == "1")
        {
            return(true);
        }
        return(false);
    }
Ejemplo n.º 9
0
    public static void PlayerLog(int pid, string what)
    {
        if (!Config.DbLogsEnabled)
        {
            return;
        }

        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?pid", pid),
            MySQL_Param.Parameter("?what", what),
        };

        Server.DB.QueryAsync("INSERT INTO [[log]].player_log (pid,what,date) VALUES (?pid,?what,NOW())", _params);
    }
Ejemplo n.º 10
0
    private static async Task <int> getPidFromSessionId(int sid)
    {
        int pid = -1;
        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?session", sid),
        };
        DataTable result = await Server.DB.QueryAsync("SELECT `pid` FROM [[player]].sessions WHERE `session`=?session LIMIT 1", _params);

        if (result.Rows[0] == null)
        {
            return(-1);
        }
        Int32.TryParse(result.Rows[0]["pid"].ToString(), out pid);
        return(pid);
    }
Ejemplo n.º 11
0
    public static void ItemLog(int vnum, long iid, string action)
    {
        if (!Config.DbLogsEnabled)
        {
            return;
        }

        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?vnum", vnum),
            MySQL_Param.Parameter("?iid", iid),
            MySQL_Param.Parameter("?action", action),
        };

        Server.DB.QueryAsync("INSERT INTO [[log]].item_log (vnum,iid,action,date) VALUES (?vnum,?iid,?action,NOW())", _params);
    }
Ejemplo n.º 12
0
    public static async Task <SessionErrorCodes> VerifySessionInDatabase(int cid, int session)
    {
        List <MySqlParameter> sessParams = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?session", Server.the_core.Clients[cid].session_id),
            MySQL_Param.Parameter("?aid", Server.the_core.Clients[cid].aid)
        };
        DataTable result = await Server.DB.QueryAsync("SELECT COUNT(*) as count FROM [[player]].sessions WHERE `session`=?session AND `aid`=?aid LIMIT 1", sessParams);

        Int32.TryParse(result.Rows[0]["count"].ToString(), out int count);
        if (count == 0)
        {
            return(SessionErrorCodes.NON_EXISTENT);
        }

        return(SessionErrorCodes.VALID);
    }
Ejemplo n.º 13
0
    public static async void SendTargetGameServerForWarp(int fromClient, Packet packet)
    {
        AuthCore core = (AuthCore)Server.the_core;
        int      cid  = packet.ReadInt();
        int      sid  = packet.ReadInt();
        int      pid  = packet.ReadInt();
        int      map  = packet.ReadInt();

        if (!Security.ReceivedIdMatchesClientId(cid, fromClient))
        {
            AuthHelpers.SendAuthFailed(fromClient);
            return;
        }

        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?session", sid),
            MySQL_Param.Parameter("?pid", pid),
        };
        DataTable rows = await Server.DB.QueryAsync("SELECT COUNT(*) AS count FROM [[player]].sessions WHERE `session`=?session AND `pid`=?pid LIMIT 1", _params);

        if (Int32.Parse(rows.Rows[0]["count"].ToString()) > 0)
        {
            DataTable result = await AuthHelpers.GetPlayerData(pid);

            List <MySqlParameter> mapParams = new List <MySqlParameter>()
            {
                MySQL_Param.Parameter("?map", map),
                MySQL_Param.Parameter("?x", Config.SpawnPositionsForMaps[map].X),
                MySQL_Param.Parameter("?y", Config.SpawnPositionsForMaps[map].Y),
                MySQL_Param.Parameter("?z", Config.SpawnPositionsForMaps[map].Z),
                MySQL_Param.Parameter("?pid", pid),
            };
            await Server.DB.QueryAsync("UPDATE [[player]].player SET `map`=?map, `x`=?x, `y`=?y, `z`=?z WHERE `id`=?pid LIMIT 1", mapParams);

            ((AuthCore)Server.the_core).Clients[cid].session_id = sid;
            AuthHelpers.MakeClientConnectToGameServer(result, cid, map);
        }
        else
        {
            Logger.Syserr($"Player #{pid} attempted to enter map #{map} but the session missmatched (sid of {sid})");
            // todo : send a disconnect packet to the client
        }
    }
Ejemplo n.º 14
0
    public static async Task <bool> DoesAidHaveSession(int aid)
    {
        List <MySqlParameter> __params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?aid", aid),
        };
        DataTable rows = await Server.DB.QueryAsync("SELECT COUNT(*) AS `count` FROM [[player]].sessions WHERE `aid`=?aid LIMIT 1", __params);

        Int32.TryParse(rows.Rows[0]["count"].ToString(), out int count);

        if (count > 0)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Ejemplo n.º 15
0
    public async void Dispose()
    {
        await flush();

        await inventory.Flush();

        if (!warping)
        {
            List <MySqlParameter> _params = new List <MySqlParameter>()
            {
                MySQL_Param.Parameter("?session", data.sid),
                MySQL_Param.Parameter("?aid", data.aid),
                MySQL_Param.Parameter("?pid", data.pid),
            };
            await Server.DB.QueryAsync("DELETE FROM [[player]].sessions WHERE `session`=?session AND `pid`=?pid AND `aid`=?aid LIMIT 1", _params);

            Logger.Syslog($"Player with session id {data.sid} dumped and destroyed.");
        }
    }
Ejemplo n.º 16
0
    private static async Task <int[]> AssignTargetSessionToClientAndGetAccountData(int client, int sid)
    {
        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?session", sid),
        };
        DataTable result = await Server.DB.QueryAsync("SELECT * FROM [[player]].sessions WHERE `session`=?session LIMIT 1", _params);

        if (result.Rows.Count == 0)
        {
            Server.the_core.Clients[client].tcp.Disconnect(3);
            return(null);
        }

        Int32.TryParse(result.Rows[0]["pid"].ToString(), out int pid);
        Int32.TryParse(result.Rows[0]["aid"].ToString(), out int aid);
        Int32.TryParse(result.Rows[0]["session"].ToString(), out int session);
        Server.the_core.Clients[client].session_id = session;
        return(new int[] { pid, aid, session });
    }
Ejemplo n.º 17
0
    private static async Task <Item[]> getPlayerInventoryFromDatabase(int pid)
    {
        List <Item>           list    = new List <Item>();
        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?pid", pid),
        };
        DataTable rows = await Server.DB.QueryAsync("SELECT * FROM [[player]].item WHERE `owner`=?pid AND (`window`='INVENTORY' OR `window`='EQUIPABLES')", _params);

        for (int i = 0; i < rows.Rows.Count; i++)
        {
            long.TryParse(rows.Rows[i]["id"].ToString(), out long iid);
            Int32.TryParse(rows.Rows[i]["vnum"].ToString(), out int vnum);
            Item.WINDOW window = (Item.WINDOW)Enum.Parse(typeof(Item.WINDOW), rows.Rows[i]["window"].ToString());
            Int32.TryParse(rows.Rows[i]["count"].ToString(), out int count);
            Int32.TryParse(rows.Rows[i]["pos"].ToString(), out int pos);
            Item nItem = new Item(pid, window, pos, Config.Items[vnum], iid, count);
            list.Add(nItem);
        }
        return(list.ToArray());
    }
Ejemplo n.º 18
0
    public static async Task <CharacterSelectionEntry[]> GetCharactersInAccount(int aid)
    {
        List <MySqlParameter> charParam = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?id", aid),
            MySQL_Param.Parameter("?max", Config.MaxCharactersInAccount)
        };
        DataTable charRows = await Server.DB.QueryAsync("SELECT * FROM [[player]].player WHERE `aid`=?id LIMIT ?max", charParam);

        List <CharacterSelectionEntry> characters = new List <CharacterSelectionEntry>();

        for (int i = 0; i < charRows.Rows.Count; i++)
        {
            Int32.TryParse(charRows.Rows[i]["id"].ToString(), out int pid);
            string name = charRows.Rows[i]["name"].ToString();
            characters.Add(new CharacterSelectionEntry(pid, name));
        }

        characters = fillMissingCharacterSlots(characters);
        return(characters.ToArray());
    }
Ejemplo n.º 19
0
    private async Task <int> flush()
    {
        List <MySqlParameter> dumpParams = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?pid", data.pid),
            MySQL_Param.Parameter("?level", data.level),
            MySQL_Param.Parameter("?exp", data.exp),
            MySQL_Param.Parameter("?vit", data.vit),
            MySQL_Param.Parameter("?str", data.str),
            MySQL_Param.Parameter("?int", data._int),
            MySQL_Param.Parameter("?dex", data.dex),
            MySQL_Param.Parameter("?x", this.data.pos.X.ToString("0.000")),
            MySQL_Param.Parameter("?y", this.data.pos.Y.ToString("0.000")),
            MySQL_Param.Parameter("?z", this.data.pos.Z.ToString("0.000")),
            MySQL_Param.Parameter("?h", this.data.heading),
            MySQL_Param.Parameter("?map", this.data.map),
        };
        await Server.DB.QueryAsync("UPDATE [[player]].player SET `level`=?level, `exp`=?exp, `vit`=?vit, `str`=?str, `int`=?int, `dex`=?dex, `x`=?x, `y`=?y, `z`=?z, `h`=?h, `map`=?map WHERE `id`=?pid LIMIT 1", dumpParams);

        return(0);
    }
Ejemplo n.º 20
0
    private static async Task <PlayerData> GetPlayerData(int client, int[] data)
    {
        int pid = data[0];
        int aid = data[1];
        int sid = data[2];

        List <MySqlParameter> __params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?pid", pid),
            MySQL_Param.Parameter("?aid", aid),
        };
        DataTable rows = await Server.DB.QueryAsync("SELECT * FROM [[player]].player WHERE `id`=?pid AND `aid`=?aid LIMIT 1", __params);

        if (rows.Rows.Count == 0)
        {
            Server.the_core.Clients[client].tcp.Disconnect(4);
            return(null);
        }

        string name = rows.Rows[0]["name"].ToString();

        float.TryParse(rows.Rows[0]["x"].ToString(), out float x);
        float.TryParse(rows.Rows[0]["y"].ToString(), out float y);
        float.TryParse(rows.Rows[0]["z"].ToString(), out float z);
        Int32.TryParse(rows.Rows[0]["h"].ToString(), out int heading);
        Int32.TryParse(rows.Rows[0]["map"].ToString(), out int map);
        Int32.TryParse(rows.Rows[0]["sex"].ToString(), out int sex);
        Int32.TryParse(rows.Rows[0]["race"].ToString(), out int race);
        Int32.TryParse(rows.Rows[0]["level"].ToString(), out int level);
        Int32.TryParse(rows.Rows[0]["exp"].ToString(), out int exp);
        Int32.TryParse(rows.Rows[0]["vit"].ToString(), out int vit);
        Int32.TryParse(rows.Rows[0]["str"].ToString(), out int str);
        Int32.TryParse(rows.Rows[0]["int"].ToString(), out int _int);
        Int32.TryParse(rows.Rows[0]["dex"].ToString(), out int dex);

        PlayerStats stats = new PlayerStats();
        PlayerData  nData = new PlayerData(pid, name, level, map, (PLAYER_SEXES)sex, (PLAYER_RACES)race, new Vector3(x, y, z), heading, stats, ANIMATION_STATES.WALK, aid, sid, 100f, 100f, exp, vit, str, _int, dex);

        return(nData);
    }
Ejemplo n.º 21
0
    private static async Task <bool> CreateAndSetNewPlayerData(int client, int[] data)
    {
        try
        {
            int pid = data[0];
            int aid = data[1];
            int sid = data[2];

            List <MySqlParameter> param = new List <MySqlParameter>()
            {
                MySQL_Param.Parameter("?pid", pid),
            };
            DataTable pResult = await Server.DB.QueryAsync("SELECT * FROM [[player]].player WHERE `id`=?pid LIMIT 1", param);

            Int32.TryParse(pResult.Rows[0]["sex"].ToString(), out int sex);
            Int32.TryParse(pResult.Rows[0]["race"].ToString(), out int race);
            Int32.TryParse(pResult.Rows[0]["level"].ToString(), out int level);
            Int32.TryParse(pResult.Rows[0]["exp"].ToString(), out int exp);
            Int32.TryParse(pResult.Rows[0]["vit"].ToString(), out int vit);
            Int32.TryParse(pResult.Rows[0]["str"].ToString(), out int str);
            Int32.TryParse(pResult.Rows[0]["int"].ToString(), out int inte);
            Int32.TryParse(pResult.Rows[0]["dex"].ToString(), out int dex);
            float.TryParse(pResult.Rows[0]["x"].ToString(), out float x);
            float.TryParse(pResult.Rows[0]["y"].ToString(), out float y);
            float.TryParse(pResult.Rows[0]["z"].ToString(), out float z);
            Vector3 pos = new Vector3(x, y, z);
            Int32.TryParse(pResult.Rows[0]["h"].ToString(), out int heading);

            PlayerStats stats     = new PlayerStats();
            PlayerData  pdata     = new PlayerData(pid, "", level, 0, (PLAYER_SEXES)sex, (PLAYER_RACES)race, pos, heading, stats, ANIMATION_STATES.WALK, aid, sid, 10f, 10f, 10f, 10f, exp, vit, str, inte, dex);
            Player      player    = new Player(Server.the_core.Clients[client], pdata, stats);
            Inventory   inventory = await Inventory.BuildInventory(player);

            player.AssignInventory(inventory);
            Server.the_core.Clients[client].setPlayer(player);
            return(true);
        } catch { return(false); }
    }
Ejemplo n.º 22
0
    public static async Task <int> GetAidFromLoginPassword(int fromClient, string user, string password)
    {
        List <MySqlParameter> _params = new List <MySqlParameter>()
        {
            MySQL_Param.Parameter("?login", user),
            MySQL_Param.Parameter("?password", password),
        };
        DataTable result = await Server.DB.QueryAsync("SELECT `id` FROM [[account]].account WHERE `login`=?login AND `password`=?password LIMIT 1", _params);

        if (result.Rows.Count == 0)
        {
            SendAuthFailed(fromClient);
            return(-1);
        }

        Int32.TryParse(result.Rows[0]["id"].ToString(), out int aid);
        if (aid <= 0)
        {
            SendAuthFailed(fromClient);
            return(-1);
        }

        return(aid);
    }