private async void CreateCharacter(ICommunicationMessage e, Character character) { // Set some values that we don't trust from the client character.Id = GuidGenerator.GenerateTimeBasedGuid(); character.UserId = e.User.Id; character.LastPlayed = DateTime.UtcNow; character.Position = new Position(0f, 0f, 71f); character.Apparel = new Apparel(); character.Appearance = new Appearance(); character.FaceShape = new FaceShape(); character.Heritage = new Heritage(); character.Armor = 0; character.Health = 100; // Store character in database using (var ctx = new StorageContext()) using (var trans = ctx.Database.BeginTransaction()) { try { ctx.Characters.Add(character); await ctx.SaveChangesAsync(); trans.Commit(); this.Logger.Debug($"Saved new character {character.FullName} for user {e.User.Name}"); // Reply with the character e.Reply(character); } catch (Exception ex) { this.Logger.Error(ex); trans.Rollback(); // TODO Reply with an error so client doesn't hang e.Reply(null); } } }
private async void RemoveMarkerEvent(ICommunicationMessage e, Guid markerId) { try { await markerManager.RemoveMarker(markerId); e.Reply(markerManager.GetAllMarkers()); } catch { e.Reply(null); } }
private async void AddMarkerEvent(ICommunicationMessage e, Marker marker) { try { await markerManager.AddMarker(marker); e.Reply(markerManager.GetAllMarkers()); } catch { e.Reply(null); } }
protected async void Create(ICommunicationMessage e) { using (var context = new StorageContext()) using (var transaction = context.Database.BeginTransaction()) { var vehicle = new Vehicle { TrackingUserId = e.User.Id, Created = DateTime.UtcNow, Position = new Position { X = float.MinValue, Y = float.MinValue, Z = float.MinValue, }, Rotation = new NFive.SDK.Core.Models.Vector3() }; context.Vehicles.Add(vehicle); await context.SaveChangesAsync(); transaction.Commit(); e.Reply(vehicle); } }
private void GetAllCharactersForUser(ICommunicationMessage e, Guid UserId) { using (var ctx = new StorageContext()) { var characters = ctx.Characters.Where(c => c.UserId == UserId && c.Deleted == null).ToList(); e.Reply(characters); } }
private void OnInitialize(ICommunicationMessage e, string clientVersion) { if (clientVersion != typeof(Program).Assembly.GetName().Version.ToString()) { this.Logger.Warn($"Client version does not match server version, got {clientVersion}, expecting {typeof(Program).Assembly.GetName().Version}, dropping client: {e.Client.Handle}"); API.DropPlayer(e.Client.Handle.ToString(), "Please reconnect to get the latest NFive client version"); return; } this.comms.Event(SessionEvents.ClientInitializing).ToServer().Emit(e.Client); var logs = new Tuple <LogLevel, LogLevel>( ServerLogConfiguration.Output.ClientConsole, ServerLogConfiguration.Output.ClientMirror ); var locale = new Tuple <List <string>, string>( ServerConfiguration.Locale.Culture.Select(c => c.Name).ToList(), TZConvert.WindowsToIana(ServerConfiguration.Locale.TimeZone.Id, new RegionInfo(ServerConfiguration.Locale.Culture.First().Name).TwoLetterISORegionName) ); e.Reply(e.User, logs, locale); }
private async void SelectCharacter(ICommunicationMessage e, Guid characterId) { await DeselectAll(e.User.Id); using (var ctx = new StorageContext()) using (var trans = ctx.Database.BeginTransaction()) { try { var character = ctx.Characters.FirstOrDefault(c => c.Id == characterId && c.UserId == e.User.Id); if (character == null) { throw new CharacterNotFoundException(characterId); } this.comms.Event(CharacterEvents.Selecting).ToServer().Emit(character); var newCharSession = new CharacterSession() { Id = GuidGenerator.GenerateTimeBasedGuid(), CharacterId = character.Id, Character = character, DateCreated = DateTime.UtcNow, DateConnected = DateTime.UtcNow, SessionId = e.Session.Id }; ctx.CharacterSessions.Add(newCharSession); await ctx.SaveChangesAsync(); trans.Commit(); this.Logger.Debug($"Created session for character {character.FullName} for user {e.User.Name}:"); this.Logger.Debug(new Serializer().Serialize(newCharSession)); newCharSession.Session = e.Session; e.Reply(newCharSession); this.CharacterSessions.Add(newCharSession); this.comms.Event(CharacterEvents.Selected).ToServer().Emit(newCharSession); } catch (Exception ex) { this.Logger.Error(ex); trans.Rollback(); e.Reply(null); } } }
private void GetCharacterById(ICommunicationMessage e, Guid characterId) { using (var ctx = new StorageContext()) { e.Reply(ctx.Characters.FirstOrDefault(c => c.Id == characterId)); } }
private void GetAllMarkersEvent(ICommunicationMessage e) { e.Reply(markerManager.GetAllMarkers()); }