private void GameStaredHandler(LobbyRoom <TAccountModel, TGame> room) { foreach (var p in room.Players) { _host.Send( new Message((short)LobbyMessages.GameStarted, Mode.Reliable, DataStorage.CreateForWrite().Push(room.RoomToken)), p.Connection); } }
private void PlayerJoinedHandler(LobbyRoom <TAccountModel, TGame> room, TAccountModel player) { foreach (var p in room.Players) { if (p != player) { _host.Send( new Message((short)LobbyMessages.PlayerJoined, Mode.Reliable, DataStorage.CreateForWrite().Push(player.Connection.Token)), p.Connection); } else { _host.Send(new Message((short)LobbyMessages.SuccesfullyJoined, Mode.Reliable), p.Connection); } } }
private void CreateRoom(TAccountModel host) { if (host.RoomToken != null) { return; } var room = new LobbyRoom <TAccountModel, TGame>(2, 2); room.PlayerJoined += PlayerJoinedHandler; room.PlayerLeaved += PlayerLeavedHander; room.GameStarted += GameStaredHandler; room.Join(host); lock (_rooms) { if (!_rooms.ContainsKey(host.Connection.Token)) { _rooms.Add(room.RoomToken, room); _host.Send( new Message((short)LobbyMessages.RoomCreated, Mode.Reliable, DataStorage.CreateForWrite().Push(room.RoomToken)), host.Connection); } } }