Ejemplo n.º 1
0
        public async Task HandleConfirmJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var joinRequest = new ConfirmJoinRequest(peer.Protocol, operationRequest);

            if (!peer.ValidateOperation(joinRequest, sendParameters))
            {
                return;
            }

            //string playerInfoStr = await WebHelper.RequestPlayerInfo(joinRequest.UserKey);
            string playerInfoStr = "{ \"username\": \"test\", \"game_money\": 2000 }";

            PlayerInfo info = JsonConvert.DeserializeObject <PlayerInfo>(playerInfoStr);

            PeerManager.Instance.OnPeerJoin(peer, new PeerInfo(peer, joinRequest.RoomID, joinRequest.UserKey));

            var room = FindRoom(joinRequest.RoomID);

            if (room != null)
            {
                room.ExecutionFiber.Enqueue(() => room.Join(peer, joinRequest, sendParameters, info));
            }
            else
            {
                var response = new OperationResponse(CommonOperationCode.ConfirmJoin,
                                                     new Dictionary <byte, object> {
                    { (byte)CommonParameterKey.Success, false }
                });
                peer.SendOperationResponse(response, sendParameters);
            }
        }
Ejemplo n.º 2
0
        public void SendAllRoomStatus(GamePeer peer, SendParameters sendParameters)
        {
            GetRoomsResponse response = new GetRoomsResponse();

            response.RoomProperties = PacketHelper.Serialize <RoomPropertyList>(GetRoomProperties());
            peer.SendOperationResponse(new OperationResponse(CommonOperationCode.GetRooms, response), sendParameters);
        }
Ejemplo n.º 3
0
        public void BroadcastBet(GamePeer peer, BroadcastBetRequest broadcastBet)
        {
            broadcastBet.Actor = playerManager.GetPlayer(peer).key.ID;
            var eventData = new EventData(EventCode.BaccaratBroadcastBet) { Parameters = broadcastBet.OperationRequest.Parameters };

            lock (syncRoot)
            {
                BroadcastMessage(peer, eventData, new SendParameters());
            }

            var response = new OperationResponse(CommonOperationCode.BaccaratBroadcastBet, new Dictionary<byte, object> { { (byte)CommonParameterKey.Success, true } });
            peer.SendOperationResponse(response, new SendParameters());
        }
Ejemplo n.º 4
0
        public void Chat(GamePeer peer, ChatRequest chatReq, SendParameters sendParameters)
        {
            var eventData = new EventData(EventCode.Chat)
            {
                Parameters = chatReq.OperationRequest.Parameters
            };

            lock (syncRoot)
            {
                BroadcastMessage(peer, eventData, sendParameters);
            }

            var response = new OperationResponse(CommonOperationCode.Chat);

            peer.SendOperationResponse(response, sendParameters);
        }
Ejemplo n.º 5
0
        public void HandleJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var joinRequest = new JoinRequest(peer.Protocol, operationRequest);
            if (!peer.ValidateOperation(joinRequest, sendParameters))
            {
                return;
            }

            var room = FindRoom(joinRequest.RoomID);

            var response = new OperationResponse(CommonOperationCode.Join,
                   new Dictionary<byte, object> { { (byte)CommonParameterKey.Success, false } });
            response.Parameters[(byte)JoinParameterKey.RoomID] = joinRequest.RoomID;

            if (room != null && room.CanJoin(peer))
            {
                response.Parameters[(byte)CommonParameterKey.Success] = true;
            }
            peer.SendOperationResponse(response, sendParameters);
        }
Ejemplo n.º 6
0
        public void Join(GamePeer peer, ConfirmJoinRequest joinReq, SendParameters sendParameters, PlayerInfo info)
        {
            if (CanJoin(peer))
            {
                Player newPlayer = playerManager.AddPlayer(peer, info);

                BroadcastMessageHandler += peer.OnBroadcastMessage;
                peer.OnLeaveHandler     += OnPeerLeave;

                OnJoin(peer);
            }
            else
            {
                var response = new OperationResponse(CommonOperationCode.ConfirmJoin,
                                                     new Dictionary <byte, object> {
                    { (byte)CommonParameterKey.Success, false }
                });

                peer.SendOperationResponse(response, sendParameters);
            }
        }
Ejemplo n.º 7
0
        public void HandleJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var joinRequest = new JoinRequest(peer.Protocol, operationRequest);

            if (!peer.ValidateOperation(joinRequest, sendParameters))
            {
                return;
            }

            var room = FindRoom(joinRequest.RoomID);

            var response = new OperationResponse(CommonOperationCode.Join,
                                                 new Dictionary <byte, object> {
                { (byte)CommonParameterKey.Success, false }
            });

            response.Parameters[(byte)JoinParameterKey.RoomID] = joinRequest.RoomID;

            if (room != null && room.CanJoin(peer))
            {
                response.Parameters[(byte)CommonParameterKey.Success] = true;
            }
            peer.SendOperationResponse(response, sendParameters);
        }
Ejemplo n.º 8
0
        public void Chat(GamePeer peer, ChatRequest chatReq, SendParameters sendParameters)
        {
            var eventData = new EventData(EventCode.Chat) { Parameters = chatReq.OperationRequest.Parameters };
            lock (syncRoot)
            {
                BroadcastMessage(peer, eventData, sendParameters);
            }

            var response = new OperationResponse(CommonOperationCode.Chat);
            peer.SendOperationResponse(response, sendParameters);
        }
Ejemplo n.º 9
0
        public void Join(GamePeer peer, ConfirmJoinRequest joinReq, SendParameters sendParameters, PlayerInfo info)
        {
            if (CanJoin(peer))
            {
                Player newPlayer = playerManager.AddPlayer(peer, info);

                BroadcastMessageHandler += peer.OnBroadcastMessage;
                peer.OnLeaveHandler += OnPeerLeave;

                OnJoin(peer);
            }
            else
            {
                var response = new OperationResponse(CommonOperationCode.ConfirmJoin,
                new Dictionary<byte, object> { { (byte)CommonParameterKey.Success, false } });

                peer.SendOperationResponse(response, sendParameters);
            }
        }
Ejemplo n.º 10
0
        public async Task HandleConfirmJoinOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var joinRequest = new ConfirmJoinRequest(peer.Protocol, operationRequest);
            if (!peer.ValidateOperation(joinRequest, sendParameters))
            {
                return;
            }

            //string playerInfoStr = await WebHelper.RequestPlayerInfo(joinRequest.UserKey);
            string playerInfoStr = "{ \"username\": \"test\", \"game_money\": 2000 }";

            PlayerInfo info = JsonConvert.DeserializeObject<PlayerInfo>(playerInfoStr);

            PeerManager.Instance.OnPeerJoin(peer, new PeerInfo(peer, joinRequest.RoomID, joinRequest.UserKey));

            var room = FindRoom(joinRequest.RoomID);

            if (room != null)
            {
                room.ExecutionFiber.Enqueue(() => room.Join(peer, joinRequest, sendParameters, info));
            }
            else
            {
                var response = new OperationResponse(CommonOperationCode.ConfirmJoin,
                new Dictionary<byte, object> { { (byte)CommonParameterKey.Success, false } });
                peer.SendOperationResponse(response, sendParameters);
            }
        }
Ejemplo n.º 11
0
 public void SendAllRoomStatus(GamePeer peer, SendParameters sendParameters)
 {
     GetRoomsResponse response = new GetRoomsResponse();
     response.RoomProperties = PacketHelper.Serialize<RoomPropertyList>(GetRoomProperties());
     peer.SendOperationResponse(new OperationResponse(CommonOperationCode.GetRooms, response), sendParameters);
 }
Ejemplo n.º 12
0
        protected override void OnJoin(GamePeer peer)
        {
            BaccaratPlayer player = playerManager.GetPlayer(peer) as BaccaratPlayer;
            SitInEmptySeat(player);

            NewPlayerJoinEvent newJoin = new NewPlayerJoinEvent();
            newJoin.Actor = player.key.ID;
            newJoin.Money = player.money;
            newJoin.Name = player.name;
            newJoin.Seat = player.seat;

            EventData eventData = new EventData(EventCode.PlayerJoin,newJoin);
            BroadcastMessage(peer, eventData, new SendParameters());

            ConfirmJoinResponse joinRes = new ConfirmJoinResponse();
            joinRes.Actor = player.key.ID;
            joinRes.Seat = player.seat;
            joinRes.Money = player.money;
            ExistingPlayerInfos infos;
            infos.infos = new List<ExistingPlayerInfo>();

            playerManager.ForEach((roomPlayer) =>
            {
                var bRoomPlayer = roomPlayer as BaccaratPlayer;
                if (bRoomPlayer.key.ID == player.key.ID) return;
                ExistingPlayerInfo pInfo;
                pInfo.ID = bRoomPlayer.key.ID;
                pInfo.Name = bRoomPlayer.name;
                pInfo.Seat = bRoomPlayer.seat;
                pInfo.Money = bRoomPlayer.money;
                pInfo.Bet = GetBet(bRoomPlayer);

                infos.infos.Add(pInfo);
            });
            joinRes.OtherPlayerInfos = PacketHelper.Serialize<ExistingPlayerInfos>(infos);

            var response = new OperationResponse(CommonOperationCode.ConfirmJoin, joinRes);

            peer.SendOperationResponse(response, new SendParameters());

            if (playerManager.Count == 1)
            {
                ClearGame();
                StartGame();
            }
        }