Exemplo n.º 1
0
        protected override Player MakePlayer(GamePeer peer, PlayerInfo info)
        {
            //Get Info from webserver
            BlackjackPlayer newPlayer = new BlackjackPlayer(peer, info);

            return newPlayer;
        }
Exemplo n.º 2
0
        public static PlayerKey MakeFromPeer(GamePeer peer)
        {
            PlayerKey key;

            key.ID = peer.ConnectionId;
            return(key);
        }
Exemplo n.º 3
0
 public void OnBroadcastMessage(GamePeer peer, EventData eventData, SendParameters sendParameters)
 {
     if (peer != this)
     {
         this.SendEvent(eventData, sendParameters);
     }
 }
Exemplo n.º 4
0
        public virtual void HandleOperationRequest(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            switch (operationRequest.OperationCode)
            {
                case CommonOperationCode.Join:
                    HandleJoinOperation(peer, operationRequest, sendParameters);
                    break;

                case CommonOperationCode.Exit:
                    HandleExitOperation(peer, operationRequest, sendParameters);
                    break;

                case CommonOperationCode.Chat:
                    HandleChatOperation(peer, operationRequest, sendParameters);
                    break;

                case CommonOperationCode.GetRooms:
                    SendAllRoomStatus(peer, sendParameters);
                    break;

                case CommonOperationCode.ConfirmJoin:
                    var task = HandleConfirmJoinOperation(peer, operationRequest, sendParameters);
                    task.Wait();
                    break;
            }
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 6
0
        public virtual void HandleOperationRequest(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            switch (operationRequest.OperationCode)
            {
            case CommonOperationCode.Join:
                HandleJoinOperation(peer, operationRequest, sendParameters);
                break;

            case CommonOperationCode.Exit:
                HandleExitOperation(peer, operationRequest, sendParameters);
                break;

            case CommonOperationCode.Chat:
                HandleChatOperation(peer, operationRequest, sendParameters);
                break;

            case CommonOperationCode.GetRooms:
                SendAllRoomStatus(peer, sendParameters);
                break;

            case CommonOperationCode.ConfirmJoin:
                var task = HandleConfirmJoinOperation(peer, operationRequest, sendParameters);
                task.Wait();
                break;
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 public void OnBroadcastMessage(GamePeer peer, EventData eventData, SendParameters sendParameters)
 {
     if (peer != this)
     {
         this.SendEvent(eventData, sendParameters);
     }
 }
Exemplo n.º 10
0
 public BaccaratPlayer(GamePeer peer, PlayerInfo info)
     : base(peer, info)
 {
     money = info.game_money;
     win = 0;
     lose = 0;
 }
Exemplo n.º 11
0
 public BlackjackPlayer(GamePeer peer, PlayerInfo info)
     : base(peer, info)
 {
     money = info.game_money;
     win = 0;
     lose = 0;
     status = PlayerStatus.Waiting;
 }
Exemplo n.º 12
0
 public void RemovePlayer(GamePeer peer)
 {
     lock (playerLock)
     {
         PlayerKey pKey = PlayerKey.MakeFromPeer(peer);
         playersDic.Remove(pKey);
     }
 }
Exemplo n.º 13
0
 public Player AddPlayer(GamePeer peer, PlayerInfo info)
 {
     lock (playerLock)
     {
         Player newPlayer = MakePlayer(peer, info);
         playersDic.Add(newPlayer.key, newPlayer);
         return(newPlayer);
     }
 }
Exemplo n.º 14
0
        public void OnPeerJoin(GamePeer peer, PeerInfo info)
        {
            ClearPeerInfo(peer);

            peersDic.Add(peer.ConnectionId, peer);
            peerInfosDic.Add(peer.ConnectionId, info);

            peer.OnLeaveHandler += OnPeerLeave;
        }
Exemplo n.º 15
0
        protected void BroadcastMessage(GamePeer peer, EventData eventData, SendParameters sendParameters)
        {
            if (BroadcastMessageHandler == null)
            {
                return;
            }

            BroadcastMessageHandler(peer, eventData, sendParameters);
        }
Exemplo n.º 16
0
        public void OnPeerJoin(GamePeer peer, PeerInfo info)
        {
            ClearPeerInfo(peer);

            peersDic.Add(peer.ConnectionId, peer);
            peerInfosDic.Add(peer.ConnectionId, info);

            peer.OnLeaveHandler += OnPeerLeave;
        }
Exemplo n.º 17
0
        public override void RemovePlayer(GamePeer peer, ExitRequest exitReq, SendParameters sendParameters)
        {
            BaccaratPlayer player = playerManager.GetPlayer(peer) as BaccaratPlayer;
            playersBetDic.Remove(player);
            seatsDic.Remove(player.seat);

            base.RemovePlayer(peer, exitReq, sendParameters);

            CheckAllBet();
        }
Exemplo n.º 18
0
        public Player GetPlayer(GamePeer peer)
        {
            PlayerKey key = PlayerKey.MakeFromPeer(peer);

            if (playersDic.ContainsKey(key))
            {
                return(playersDic[key]);
            }

            return(null);
        }
Exemplo n.º 19
0
        private void HandleBetRequest(GamePeer gamePeer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var room = FindPeerRoom(gamePeer) as BaccaratGameRoom;

            var sendBetRequest = new SendBetRequest(gamePeer.Protocol, operationRequest);

            if (room != null)
            {
                room.Bet(gamePeer, sendBetRequest);
            }
        }
Exemplo n.º 20
0
        private void HandleBetBroadcastRequest(GamePeer gamePeer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var room = FindPeerRoom(gamePeer) as BlackjackGameRoom;

            var betBroadcast = new BroadcastBetRequest(gamePeer.Protocol, operationRequest);

            if (room != null)
            {
                room.BroadcastBet(gamePeer, betBroadcast);
            }
        }
Exemplo n.º 21
0
        private void HandleActionRequest(GamePeer gamePeer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var room = FindPeerRoom(gamePeer) as BlackjackGameRoom;

            var actionRequest = new ActionRequest(gamePeer.Protocol, operationRequest);

            if (room != null)
            {
                room.OnPlayerAction(gamePeer, actionRequest);
            }
        }
Exemplo n.º 22
0
        private void ClearPeerInfo(GamePeer peer)
        {
            if (peersDic.ContainsKey(peer.ConnectionId))
            {
                peersDic.Remove(peer.ConnectionId);
            }

            if (peerInfosDic.ContainsKey(peer.ConnectionId))
            {
                peerInfosDic.Remove(peer.ConnectionId);
            }
        }
Exemplo n.º 23
0
        private void ClearPeerInfo(GamePeer peer)
        {
            if (peersDic.ContainsKey(peer.ConnectionId))
            {
                peersDic.Remove(peer.ConnectionId);
            }

            if (peerInfosDic.ContainsKey(peer.ConnectionId))
            {
                peerInfosDic.Remove(peer.ConnectionId);
            }
        }
Exemplo n.º 24
0
        protected GameRoom FindPeerRoom(GamePeer peer)
        {
            foreach (var room in roomsDic.Values)
            {
                if (room.HasPlayer(peer))
                {
                    return(room);
                }
            }

            return(null);
        }
Exemplo n.º 25
0
        public bool HasPlayer(GamePeer peer)
        {
            PlayerKey pKey;

            pKey.ID = peer.ConnectionId;

            if (playersDic.ContainsKey(pKey))
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 26
0
        public void Bet(GamePeer peer, SendBetRequest sendBet)
        {
            BaccaratPlayer player = playerManager.GetPlayer(peer) as BaccaratPlayer;
            var bet = new BaccaratBet(sendBet.BankerBet, sendBet.PlayerBet, sendBet.TieBet);

            if (HasBet(player) == false && CanBet(player, bet))
            {
                playersBetDic.Add(player, bet);
            }

            CheckAllBet();
        }
Exemplo n.º 27
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());
        }
Exemplo n.º 28
0
        public bool CanJoin(GamePeer peer)
        {
            if (playerManager.HasPlayer(peer))
            {
                return false; //already joined.
            }

            if (playerManager.isFull())
            {
                return false; //exceed max player count.
            }

            return true;
        }
Exemplo n.º 29
0
        public bool CanJoin(GamePeer peer)
        {
            if (playerManager.HasPlayer(peer))
            {
                return(false); //already joined.
            }

            if (playerManager.isFull())
            {
                return(false); //exceed max player count.
            }

            return(true);
        }
Exemplo n.º 30
0
        public override void HandleOperationRequest(GamePeer gamePeer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            base.HandleOperationRequest(gamePeer, operationRequest, sendParameters);
            //nothing

            switch(operationRequest.OperationCode)
            {
                case CommonOperationCode.BaccaratBet:
                    HandleBetRequest(gamePeer, operationRequest, sendParameters);
                    break;

                case CommonOperationCode.BaccaratBroadcastBet:
                    HandleBetBroadcastRequest(gamePeer, operationRequest, sendParameters);
                    break;
            }
        }
Exemplo n.º 31
0
        public void HandleChatOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var chatRequest = new ChatRequest(peer.Protocol, operationRequest);

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

            var room = FindPeerRoom(peer);

            if (room != null)
            {
                room.Chat(peer, chatRequest, sendParameters);
            }
        }
Exemplo n.º 32
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);
        }
Exemplo n.º 33
0
        public void HandleExitOperation(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var exitRequest = new ExitRequest(peer.Protocol, operationRequest);

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

            var room = FindPeerRoom(peer);

            if (room != null)
            {
                room.ExecutionFiber.Enqueue(() => room.Leave(peer));
            }
            peer.Leave();
        }
Exemplo n.º 34
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);
        }
Exemplo n.º 35
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);
            }
        }
Exemplo n.º 36
0
        public virtual void RemovePlayer(GamePeer peer, ExitRequest exitReq, SendParameters sendParameters)
        {
            lock (syncRoot)
            {
                if (playerManager.HasPlayer(peer) == false)
                {
                    return; //already removed.
                }

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

                PlayerLeaveEvent leaveEvent = new PlayerLeaveEvent();
                leaveEvent.Actor = playerManager.GetPlayer(peer).key.ID;

                EventData eventData = new EventData(EventCode.PlayerLeave, leaveEvent);
                BroadcastMessage(peer, eventData, sendParameters);

                playerManager.RemovePlayer(peer);
            }
        }
Exemplo n.º 37
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);
        }
Exemplo n.º 38
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);
            }
        }
Exemplo n.º 39
0
 public void Leave(GamePeer peer)
 {
     OnPeerLeave(peer);
 }
Exemplo n.º 40
0
 protected abstract void OnJoin(GamePeer peer);
Exemplo n.º 41
0
 public bool HasPlayer(GamePeer peer)
 {
     return playerManager.HasPlayer(peer);
 }
Exemplo n.º 42
0
 public void HandleOperationRequest(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
 {
     gameCore.HandleOperationRequest(peer, operationRequest, sendParameters);
 }
Exemplo n.º 43
0
 public void Leave(GamePeer peer)
 {
     OnPeerLeave(peer);
 }
Exemplo n.º 44
0
 protected abstract void OnJoin(GamePeer peer);
Exemplo n.º 45
0
 public PeerInfo GetPeerInfo(GamePeer peer)
 {
     return(peerInfosDic.ContainsKey(peer.ConnectionId) ? peerInfosDic[peer.ConnectionId] : null);
 }
Exemplo n.º 46
0
        public virtual void RemovePlayer(GamePeer peer, ExitRequest exitReq, SendParameters sendParameters)
        {
            lock (syncRoot)
            {
                if (playerManager.HasPlayer(peer) == false)
                {
                    return; //already removed.
                }

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

                PlayerLeaveEvent leaveEvent = new PlayerLeaveEvent();
                leaveEvent.Actor = playerManager.GetPlayer(peer).key.ID;

                EventData eventData = new EventData(EventCode.PlayerLeave, leaveEvent);
                BroadcastMessage(peer, eventData, sendParameters);

                playerManager.RemovePlayer(peer);

            }
        }
Exemplo n.º 47
0
 public void HandleOperationRequest(GamePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
 {
     gameCore.HandleOperationRequest(peer, operationRequest, sendParameters);
 }
Exemplo n.º 48
0
 public PeerInfo(GamePeer peer, int roomID, string userKey)
 {
     this.connectionID = peer.ConnectionId;
     this.roomID       = roomID;
     this.userKey      = userKey;
 }
Exemplo n.º 49
0
        protected GameRoom FindPeerRoom(GamePeer peer)
        {
            foreach (var room in roomsDic.Values)
            {
                if (room.HasPlayer(peer))
                {
                    return room;
                }
            }

            return null;
        }
Exemplo n.º 50
0
 private void OnPeerLeave(GamePeer peer)
 {
     RemovePlayer(peer, null, new SendParameters());
 }
Exemplo n.º 51
0
        protected void BroadcastMessage(GamePeer peer, EventData eventData, SendParameters sendParameters)
        {
            if (BroadcastMessageHandler == null) return;

            BroadcastMessageHandler(peer, eventData, sendParameters);
        }
Exemplo n.º 52
0
 protected abstract Player MakePlayer(GamePeer peer, PlayerInfo info);
Exemplo n.º 53
0
 private void OnPeerLeave(GamePeer peer)
 {
     RemovePlayer(peer, null, new SendParameters());
 }
Exemplo n.º 54
0
 public PeerInfo GetPeerInfo(GamePeer peer)
 {
     return peerInfosDic.ContainsKey(peer.ConnectionId) ? peerInfosDic[peer.ConnectionId] : null;
 }
Exemplo n.º 55
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);
        }
Exemplo n.º 56
0
 public void HandleDisconnect(GamePeer peer)
 {
     peer.Leave();
 }
Exemplo n.º 57
0
 public void OnPeerLeave(GamePeer peer)
 {
     ClearPeerInfo(peer);
 }
Exemplo n.º 58
0
 public void OnPeerLeave(GamePeer peer)
 {
     ClearPeerInfo(peer);
 }
Exemplo n.º 59
0
 public Player(GamePeer peer, PlayerInfo info)
 {
     this.peer = peer;
     this.key = PlayerKey.MakeFromPeer(peer);
     this.name = info.username;
 }
Exemplo n.º 60
0
 public bool HasPlayer(GamePeer peer)
 {
     return(playerManager.HasPlayer(peer));
 }