Ejemplo n.º 1
0
 private void CreateGameSession(MatchWaiting <TAccountModel> sender, TAccountModel[] players)
 {
     sender.BackToQueue       -= ReturnToQueue;
     sender.OnValidateSuccess -= CreateGameSession;
     if (RoomCreated != null)
     {
         RoomCreated.Invoke(players);
     }
 }
Ejemplo n.º 2
0
        private void HandleSocketMessage(object sender, MessageEventArgs e)
        {
            var message = e.Data;

            try
            {
                var baseMessage = JsonConvert.DeserializeObject <BaseMessage>(message);
                if (baseMessage.Type == SocketMessageTypes.SuccessfullyAuthorized)
                {
                    Authorized?.Invoke();
                }
                else if (baseMessage.Type == SocketMessageTypes.RoomCreated)
                {
                    var response = JsonConvert.DeserializeObject <SocketResponseDTO <RoomDTO> >(message);
                    RoomCreated?.Invoke(response);
                }
                else if (baseMessage.Type == SocketMessageTypes.NewMessage)
                {
                    var response = JsonConvert.DeserializeObject <SocketResponseDTO <MessageDTO> >(message);
                    NewMessageReceived?.Invoke(response);
                }
                else if (baseMessage.Type == SocketMessageTypes.RoomParticipated)
                {
                    var response = JsonConvert.DeserializeObject <SocketResponseDTO <RoomParticipatedDTO> >(message);
                    RoomParticipated?.Invoke(response);
                }
                else if (baseMessage.Type == SocketMessageTypes.RoomLeft)
                {
                    var response = JsonConvert.DeserializeObject <SocketResponseDTO <RoomParticipatedDTO> >(message);
                    RoomLeft?.Invoke(response);
                }
                else if (baseMessage.Type == SocketMessageTypes.FileStatusChanged)
                {
                    var response = JsonConvert.DeserializeObject <SocketResponseDTO <FileStatusDTO> >(message);
                    FileStatusChanged?.Invoke(response);
                }
            }
            catch (Exception ex)
            {
                Failed?.Invoke(ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void EventReceivedHandler(object sender, EvmChainEventArgs e)
        {
            //Debug.Log("Event: " + e.EventName);
            switch (e.EventName)
            {
            case "RoomCreated":
            {
                RoomCreatedEventData eventDto = e.DecodeEventDto <RoomCreatedEventData>();
                this.eventActions.Enqueue(() => RoomCreated?.Invoke((Address)eventDto.Creator, eventDto.RoomId));
                break;
            }

            case "PlayerJoined":
            {
                PlayerJoinedEventData eventDto = e.DecodeEventDto <PlayerJoinedEventData>();
                this.eventActions.Enqueue(() => PlayerJoined?.Invoke(eventDto.RoomId, (Address)eventDto.Player));
                break;
            }

            case "GameStageChanged":
            {
                GameStageChangedEventData eventDto = e.DecodeEventDto <GameStageChangedEventData>();
                this.eventActions.Enqueue(() => GameStageChanged?.Invoke(eventDto.RoomId, eventDto.Stage));
                break;
            }

            case "CurrentPlayerIndexChanged":
            {
                CurrentPlayerIndexChangedEventData eventDto = e.DecodeEventDto <CurrentPlayerIndexChangedEventData>();
                this.eventActions.Enqueue(() => CurrentPlayerIndexChanged?.Invoke(eventDto.RoomId, eventDto.PlayerIndex, (Address)eventDto.PlayerAddress));
                break;
            }

            case "PlayerDecisionReceived":
            {
                PlayerDecisionReceivedEventData eventDto = e.DecodeEventDto <PlayerDecisionReceivedEventData>();
                this.eventActions.Enqueue(() => PlayerDecisionReceived?.Invoke(eventDto.RoomId, eventDto.PlayerIndex, (Address)eventDto.PlayerAddress, eventDto.PlayerDecision));
                break;
            }
            }
        }
Ejemplo n.º 4
0
 protected virtual void OnRoomCreated(Room room)
 {
     RoomCreated?.Invoke(room);
 }
 private void EventReceivedHandler(object sender, EvmChainEventArgs e)
 {
     lock (this.roomIdToRoomEventActionsMap)
     {
         switch (e.EventName)
         {
             case "RoomCreated":
             {
                 RoomCreatedEventData eventDto = e.DecodeEventDto<RoomCreatedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     -1,
                     () => RoomCreated?.Invoke((Address) eventDto.Creator, eventDto.RoomId)
                     );
                 break;
             }
             case "PlayerJoined":
             {
                 PlayerRelatedEventData eventDto = e.DecodeEventDto<PlayerRelatedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => PlayerJoined?.Invoke(eventDto.RoomId, (Address) eventDto.Player)
                 );
                 break;
             }
             case "PlayerLeft":
             {
                 PlayerRelatedEventData eventDto = e.DecodeEventDto<PlayerRelatedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => PlayerLeft?.Invoke(eventDto.RoomId, (Address) eventDto.Player)
                 );
                 break;
             }
             case "PlayerBetted":
             {
                 PlayerBettedEventData eventDto = e.DecodeEventDto<PlayerBettedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => PlayerBetted?.Invoke(eventDto.RoomId, (Address) eventDto.Player, eventDto.Bet)
                 );
                 break;
             }
             case "PlayerReadyForNextRoundChanged":
             {
                 PlayerReadyForNextRoundChangedEventData eventDto = e.DecodeEventDto<PlayerReadyForNextRoundChangedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => PlayerReadyForNextRoundChanged?.Invoke(eventDto.RoomId, (Address) eventDto.Player, eventDto.Ready)
                 );
                 break;
             }
             case "GameStageChanged":
             {
                 GameStageChangedEventData eventDto = e.DecodeEventDto<GameStageChangedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => GameStageChanged?.Invoke(eventDto.RoomId, eventDto.Stage)
                 );
                 break;
             }
             case "CurrentPlayerIndexChanged":
             {
                 CurrentPlayerIndexChangedEventData eventDto = e.DecodeEventDto<CurrentPlayerIndexChangedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => CurrentPlayerIndexChanged?.Invoke(eventDto.RoomId, eventDto.PlayerIndex, (Address) eventDto.PlayerAddress)
                 );
                 break;
             }
             case "PlayerDecisionReceived":
             {
                 PlayerDecisionReceivedEventData eventDto = e.DecodeEventDto<PlayerDecisionReceivedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => PlayerDecisionReceived?.Invoke(eventDto.RoomId, (Address) eventDto.Player, eventDto.PlayerDecision)
                 );
                 break;
             }
             case "GameRoundResultsAnnounced":
             {
                 GameRoundResultsAnnouncedEventData eventDto = e.DecodeEventDto<GameRoundResultsAnnouncedEventData>();
                 EnqueueRoomEventAction(
                     eventDto.RoomId,
                     eventDto.Nonce,
                     () => GameRoundResultsAnnounced?.Invoke(
                         eventDto.RoomId,
                         eventDto.DealerOutcome,
                         eventDto.Players.Select(p => (Address) p).ToArray(),
                         eventDto.PlayerOutcome.ToArray())
                 );
                 break;
             }
             case "Log":
             {
                 break;
             }
             default:
                 throw new ArgumentOutOfRangeException($"Unknown event {e.EventName}");
         }
     }
 }
Ejemplo n.º 6
0
        public void Bind(Host host)
        {
            _host = host;
            _host.AddHandler((short)LobbyMessages.RoomCreated, (m, c) => {
                if (RoomCreated != null)
                {
                    var ds        = DataStorage.CreateForRead(m.Body);
                    var roomToken = new Token();
                    roomToken.ReadFromDs(ds);

                    RoomCreated.Invoke(roomToken);
                }
            });
            _host.AddHandler((short)LobbyMessages.PlayerLeaved, (m, c) => {
                if (OnPlayerLeaved != null)
                {
                    var ds          = DataStorage.CreateForRead(m.Body);
                    var playerToken = new Token();
                    playerToken.ReadFromDs(ds);
                    OnPlayerLeaved.Invoke(playerToken);
                }
            });
            _host.AddHandler((short)LobbyMessages.SuccesfullyLeaved, (m, c) => {
                if (OnLeave != null)
                {
                    OnLeave.Invoke();
                }
            });
            _host.AddHandler((short)LobbyMessages.PlayerJoined, (m, c) => {
                if (OnPlayerJoined != null)
                {
                    var ds          = DataStorage.CreateForRead(m.Body);
                    var playerToken = new Token();
                    playerToken.ReadFromDs(ds);
                    OnPlayerJoined.Invoke(playerToken);
                }
            });
            _host.AddHandler((short)LobbyMessages.SuccesfullyJoined, (m, c) => {
                if (OnJoin != null)
                {
                    OnJoin.Invoke();
                }
            });
            _host.AddHandler((short)LobbyMessages.GameStarted, (m, c) => {
                if (OnGameStarted != null)
                {
                    var ds     = DataStorage.CreateForRead(m.Body);
                    _roomToken = new Token();
                    _roomToken.ReadFromDs(ds);
                    OnGameStarted.Invoke();
                }
            });
            _host.AddHandler((short)LobbyMessages.GetRoomsResponse, (m, c) => {
                if (OnRoomInfoRecieved != null)
                {
                    var roomTokens = new List <Token>();
                    roomTokens.FillDeserialize(m.Body);
                    OnRoomInfoRecieved.Invoke(roomTokens);
                }
            });
        }
Ejemplo n.º 7
0
 private static void OnRoomCreated(RoomManager roomManager, Room room)
 {
     RoomCreated?.Invoke(roomManager, new RoomEventArgs(room));
 }