public ResponeCommMessage HandleEvent(CreateNewRoomMessage msg) { if (_sessionIdHandler != null) { int roomId = _gameService.CreateNewRoom(msg.UserId, msg._chipPolicy, msg._canSpectate, msg._mode, msg._minPlayer, msg._maxPlayers, msg._buyInPolicy, msg._minBet); var success = roomId != -1; CreateNewGameResponse respons; if (success) { List <string> names = new List <string>(); IUser user = _userService.GetUserById(msg.UserId); names.Add(user.MemberName()); var gameData = new GameDataCommMessage(msg.UserId, roomId, _sessionIdHandler.GetSessionIdByUserId(msg.UserId), null, null, new List <Card>(), msg._chipPolicy, 0, names, new List <string>(), null, null, null, true, "", "", 0, CommunicationMessage.ActionType.CreateRoom, GameRoom.HandStep.PreFlop.ToString(), ""); respons = new CreateNewGameResponse(msg.UserId, _sessionIdHandler.GetSessionIdByUserId(msg.UserId), success, msg, gameData); } else { respons = new CreateNewGameResponse(); } return(respons); } return(new ResponeCommMessage(msg.UserId, msg.SessionId, false, msg)); }
public GameDataCommMessage CreateNewRoom(GameMode mode, int minBet, int chipPol, int buyInPol, bool canSpec, int minPlayers, int maxPlayers) { //should ret int as the roomNumber CreateNewRoomMessage toSend = new CreateNewRoomMessage(user.id, _sessionId, mode, minBet, chipPol, buyInPol, canSpec, minPlayers, maxPlayers); Tuple <CommunicationMessage, bool, bool, ResponeCommMessage> messageToList = new Tuple <CommunicationMessage, bool, bool, ResponeCommMessage>(toSend, false, false, new ResponeCommMessage(user.id)); MessagesSentObserver.Add(messageToList); _eventHandler.SendNewEvent(toSend); while ((MessagesSentObserver.Find(x => x.Item1.Equals(toSend))).Item2 == false) { var t = Task.Run(async delegate { await Task.Delay(10); }); t.Wait(); } bool isSuccessful = (MessagesSentObserver.Find(x => x.Item1.Equals(toSend))).Item3; CreateNewGameResponse res = (CreateNewGameResponse)(MessagesSentObserver.Find(x => x.Item1.Equals(toSend))).Item4; GameDataCommMessage newRoom; if (isSuccessful) { newRoom = res.GameData; } else { newRoom = null; } MessagesSentObserver.Remove(messageToList); return(newRoom); }
public ResponeCommMessage HandleEvent(CreateNewRoomMessage msg) { GotClientToServerMsg(msg); return(new ResponeCommMessage(msg.UserId, msg.SessionId, false, msg)); }