Example #1
0
        private HiveUser NewUser(string name, string steamid, string license, string ip)
        {
            HiveUser user = new HiveUser()
            {
                Name    = name,
                SteamId = steamid,
                License = license,
                Ip      = ip
            };

            users[steamid] = user;
            return(user);
        }
Example #2
0
        private void RegisterUser([FromSource] Player player)
        {
            Ready(() =>
            {
                string steamid = player.Identifiers["steam"];
                Exports["mysql-async"].mysql_fetch_all("SELECT * FROM users WHERE steamid = @steamid;",
                                                       new Dictionary <string, object> {
                    { "@steamid", steamid }
                },
                                                       new Action <List <object> > ((List <object> result) =>
                {
                    if (result.Count > 0)
                    {
                        // user already exists in the table
                        var expando   = (dynamic)result[0];
                        HiveUser user = NewUser(expando.name, expando.steamid, expando.license, expando.ip);
                        player.TriggerEvent(HiveShared.EventRegisterUserResponse, user);
                    }
                    else
                    {
                        // new user added to table
                        string license = player.Identifiers["license"];
                        string ip      = player.Identifiers["ip"];

                        Exports["mysql-async"].mysql_insert("INSERT INTO users VALUES (@name, @steamid, @license, @ip);",
                                                            new Dictionary <string, object> {
                            { "@name", player.Name },
                            { "@steamid", steamid },
                            { "@license", license },
                            { "@ip", ip }
                        }, new Action(() => {
                            HiveUser user = NewUser(player.Name, steamid, license, ip);
                            player.TriggerEvent(HiveShared.EventRegisterUserResponse, user);
                        }), false);
                    }
                }), false);
            });
        }