public static void Register(SharpBridge.Player player, object[] param) { string pass = ((string)param[0]).ToLower(); if (pass.Length < 3 || pass.Length > 22) { player.sendMsg("Your password must contain 3-22 characters", ChatColor.ERROR); return; } try { using (Repositories.UserRepository accs = new Repositories.UserRepository()) { Models.EntityEF uc = new Models.EntityEF { items = new List <Models.ItemEF>(), user = new Models.UserEF { name = player.getNick(), password = Services.Hashing.SHA2(ref pass), clothes = "1", hp = 100, armor = 0, moneyBank = 100 }, // Spawns the player on grass, near the Broker Bus Depot, looking at Montauk Avenue x = 1075.0f, y = 278.0f, z = 30.5f, createDate = DateTime.Now }; uc.user.entity = uc; accs.entities.Add(uc); accs.SaveChanges(); player.sendMsg($"Account created with password '{pass}'. Use /login to proceed", ChatColor.SUCCESS); } } catch (DbUpdateException e) { if (e.ToString().Contains("Duplicate entry")) { player.sendMsg($"Account '{player.getNick()}' already exists. Please use /login [password]", ChatColor.ERROR); return; } Console.WriteLine(e.ToString()); } }
public static void Spawn(SharpBridge.Player player, object[] param) { string name = ((string)param[0]).ToUpper(); int vehModel = VehicleModels.getModelByName(name); if (vehModel == -1) { player.sendMsg($"'{name}' is an invalid model", ChatColor.ERROR); return; } int color = new Random().Next(0, 140); Vector3 pos = player.getPos(); pos.z += 1.0f; Vehicle veh = Entities.createVehicle(vehModel, pos, new Vector3(0.0f, 0.0f, player.getHeading()), color, color, color, color, player.getWorld()); player.sendMsg($"{name} spawned: {veh.getId()}", ChatColor.SUCCESS); }
public static void Login(SharpBridge.Player player, object[] param) { try { string gameNick = player.getNick(); if (Game.AccountManager.GetByName(ref gameNick) != null) { player.sendMsg("This account is already being used", ChatColor.ERROR); return; } string user = gameNick.ToLower(); string pass = ((string)param[0]).ToLower(); using (Repositories.UserRepository accs = new Repositories.UserRepository()) { Models.UserEF acc = accs.users.Where(i => i.name == user). Include(i => i.entity).Include(i => i.entity.items).FirstOrDefault(); if (acc == null) { player.sendMsg($"Account '{player.getNick()}' doesn't exist", ChatColor.ERROR); return; } else if (acc.password.ToLower() != Services.Hashing.SHA2(ref pass)) { player.sendMsg("Wrong password", ChatColor.ERROR); return; } Console.WriteLine(JsonConvert.SerializeObject(acc)); Game.Account playerAccount = new Game.Account(acc); Game.AccountManager.Add(player.getID(), playerAccount); playerAccount.setClothesFromString(player); player.setPos(playerAccount.getPos()); player.setHealth(acc.hp); player.setArmor(acc.armor); player.setFrozen(false); player.cam_setPos(null, 1); player.cam_attachOnPlayer(-1); player.setWorld(1); // Colors "Welcome back" green and the player’s name orange for 5 seconds player.drawInfoText($"~g~Welcome back~w~, ~COL_NET_13~'{player.getNick()}'~w~!", 5000); List <short> givenAmmoTypes = new List <short>(); foreach (var item in acc.entity.items) { Models.ItemTypesEF typ = Game.ItemTypesManager.GetItemTypeByItem(item); if (typ.weapon != null) { Console.WriteLine($"{item.type} is a weapon"); Models.ItemEF ammo = acc.entity.items.Where(j => j.type == typ.weapon.ammoItem).FirstOrDefault(); if (ammo == null || givenAmmoTypes.Count(j => j == ammo.type) != 0) { continue; } Console.WriteLine("Ammo found"); givenAmmoTypes.Add(ammo.type); player.giveWeapon((uint)item.type, (uint)ammo.amount); } } } } catch (Exception e) { Console.WriteLine(e.ToString()); } }