private void SelectCharacter([FromSource] Player _player, int _charID) { Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle); if (foundSesh == null) { return; } if (foundSesh.selectedCharacter != null) { Utils.DebugLine("Couldn't select character! A character is already selected!", "SSessionManager"); return; } Character selectedCharacter = CharacterDBManager.SelectCharacter(_player, foundSesh.User, _charID); if (selectedCharacter != null) { //If the players character is not new then we can select the character server side if (!selectedCharacter.IsNew) { foundSesh.selectedCharacter = selectedCharacter; } foundSesh.Player.TriggerEvent("Laced:SpawnPlayerCharacter", foundSesh.SessionKey, JsonConvert.SerializeObject(selectedCharacter)); } }
private void GarageStoreVehicle([FromSource] Player _player, string _seshKey, string _garageItem, NetworkCallbackDelegate _networkCallback) { if (_seshKey == null) { Utils.WriteLine($"Player[{_player.Name}] didn't have a session key!"); return; } Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle); if (foundSesh.SessionKey != _seshKey) { Utils.WriteLine($"Players[{_player.Name}] session key didn't equal servers key!"); return; } GarageItem storinggarageItem = JsonConvert.DeserializeObject <GarageItem>(_garageItem); foreach (GarageItem gI in foundSesh.selectedCharacter.Garage.garageItems) { Utils.WriteLine($"Storing vehicle[{storinggarageItem.garageID}], garage vehicle [{gI.garageID}]"); //Get the garage item in the servers memory if (storinggarageItem.garageID == gI.garageID) { //Check if the garage item is not stored and is not impounded if (ConfigManager.ServerConfig.RPImpound) { if (gI.impounded) { Utils.WriteLine("Vehicle is impounded!"); return; } } if (!gI.stored) { gI.setImpounded(false); gI.setStored(true); gI.setNetworkID(0); foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id)); _networkCallback(true); return; } } } _networkCallback(false); }
private void CreateCharacter([FromSource] Player _player, string _firstName, string _lastName, int _gender) { Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle); if (foundSesh != null) { if (foundSesh.selectedCharacter != null) { Utils.DebugLine("Couldn't create character! A character is already selected!", "SSessionManager"); return; } List <Character> newCharacters = CharacterDBManager.CreateCharacter(_player, foundSesh.User, _firstName, _lastName, (Genders)_gender); Utils.DebugLine(newCharacters.ToString(), "SSessionManager"); foundSesh.UpdateCharacters(newCharacters); foundSesh.Player.TriggerEvent("Laced:UpdateCharacterSelection", JsonConvert.SerializeObject(newCharacters)); } }
private void RetrieveGarageVehicle([FromSource] Player _player, string _seshKey, int garageID, NetworkCallbackDelegate _networkCallback) { if (_seshKey == null) { Utils.WriteLine("Session key is missing!"); return; } Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle); if (foundSesh == null || foundSesh.SessionKey != _seshKey) { Utils.WriteLine("Session either doesn't exist or the session key doesn't match up"); return; } foreach (GarageItem gI in foundSesh.selectedCharacter.Garage.garageItems) { if (gI.garageID == garageID) { if (ConfigManager.ServerConfig.RPImpound) { gI.setImpounded(false); } else { gI.setImpounded(true); } gI.setStored(false); foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id)); _networkCallback(true, JsonConvert.SerializeObject(gI)); return; } } _networkCallback(false, null); }
private void FinishCharacterEditing([FromSource] Player _player, string _sessionkey, string _characterString, NetworkCallbackDelegate _networkCallback) { if (_sessionkey == null) { Utils.WriteLine($"Player[{_player.Name}] didn't have a session key!"); return; } Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle); if (foundSesh.SessionKey != _sessionkey) { Utils.WriteLine($"Players[{_player.Name}] session key didn't equal servers key!"); return; } Utils.DebugLine("Player Character Finished Editing!", "SSessionManager"); Character character = JsonConvert.DeserializeObject <Character>(_characterString); foundSesh.selectedCharacter = character; foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, character.Id)); _networkCallback(JsonConvert.SerializeObject(character)); }
private void SellCardealerVehicle([FromSource] Player _player, string _seshKey, string _sellgarageItem, NetworkCallbackDelegate _networkCallback) { if (_seshKey == null) { Utils.WriteLine("Session key is missing!"); return; } Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle); if (foundSesh == null || foundSesh.SessionKey != _seshKey) { Utils.WriteLine("Session either doesn't exist or the session key doesn't match up"); return; } GarageItem sellgarageItem = JsonConvert.DeserializeObject <GarageItem>(_sellgarageItem); foreach (GarageItem gI in foundSesh.selectedCharacter.Garage.garageItems) { if (gI.garageID == sellgarageItem.garageID) { foreach (string key in ConfigManager.MarkerConfig.Keys) { //Find the cardealers within the markers if (key.ToLower().Contains("dealer")) { //Loop through vehicle dealer marker data foreach (string dataKey in ConfigManager.MarkerConfig[key].MarkerData.Keys) { //Get the vehicles if (dataKey.ToLower().Contains("vehicles")) { string markerDataString = JsonConvert.SerializeObject(ConfigManager.MarkerConfig[key].MarkerData[dataKey]); Dictionary <string, CardealerItem> markerData = JsonConvert.DeserializeObject <Dictionary <string, CardealerItem> >(markerDataString); foreach (string dataKey2 in markerData.Keys) { if (dataKey2.ToLower().Contains(gI.vehicleModel)) { //We have found the vehicle //We need to save the car to the garage and the garage to the database string jsonString = JsonConvert.SerializeObject(markerData[dataKey2]); CardealerItem cardealerItem = JsonConvert.DeserializeObject <CardealerItem>(jsonString); foundSesh.selectedCharacter.SellItem(cardealerItem.Price); foundSesh.selectedCharacter.SellVehicle(gI); foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id)); Utils.WriteLine("Updated character!"); try { _networkCallback(true, JsonConvert.SerializeObject(gI), cardealerItem.Price); return; } catch (Exception _ex) { Utils.Throw(_ex); } } } } } } } } } _networkCallback(false, null, 0); }
private void BuyCardealerVehicle([FromSource] Player _player, string _seshKey, string _vehicleModel, NetworkCallbackDelegate _networkCallback) { Utils.WriteLine("Buying Cardealer vehicle!"); if (_seshKey == null) { Utils.WriteLine("Session key is missing!"); return; } Session foundSesh = Sessions.Find(s => s.Player.Handle == _player.Handle); if (foundSesh == null || foundSesh.SessionKey != _seshKey) { Utils.WriteLine("Session either doesn't exist or the session key doesn't match up"); return; } Utils.WriteLine("Searching markers"); foreach (string key in ConfigManager.MarkerConfig.Keys) { //Find the cardealers within the markers if (key.ToLower().Contains("dealer")) { foreach (string dataKey in ConfigManager.MarkerConfig[key].MarkerData.Keys) { if (dataKey.ToLower().Contains("vehicles")) { string markerDataString = JsonConvert.SerializeObject(ConfigManager.MarkerConfig[key].MarkerData[dataKey]); Dictionary <string, CardealerItem> markerData = JsonConvert.DeserializeObject <Dictionary <string, CardealerItem> >(markerDataString); foreach (string dataKey2 in markerData.Keys) { if (dataKey2.ToLower().Contains(_vehicleModel)) { //We have found the vehicle //We need to save the car to the garage and the garage to the database string jsonString = JsonConvert.SerializeObject(markerData[dataKey2]); CardealerItem cardealerItem = JsonConvert.DeserializeObject <CardealerItem>(jsonString); if (!foundSesh.selectedCharacter.BuyItem(cardealerItem.Price)) { Utils.WriteLine($"Player doesn't have enough money![{foundSesh.Player.Name}]"); _networkCallback(false, null); return; } int garageID = foundSesh.selectedCharacter.Garage.garageItems.Count + 1; GarageItem garageItem = new GarageItem(garageID, foundSesh.selectedCharacter.Id, cardealerItem.CarName, cardealerItem.CarModel, Utils.CreateVehicleNumberPlate(), false, false, new Dictionary <string, int>()); if (ConfigManager.ServerConfig.RPImpound) { garageItem.setImpounded(false); } else { garageItem.setImpounded(true); } garageItem.setStored(false); foundSesh.selectedCharacter.Garage.garageItems.Add(garageItem); foundSesh.UpdateCharacters(CharacterDBManager.UpdateCharacter(_player, foundSesh.User, foundSesh.selectedCharacter.Id)); _networkCallback(true, JsonConvert.SerializeObject(garageItem)); } } } } } } }