Пример #1
0
        public void Execute <T>(ServerConnection <T> connection, IServerCommand entity)
        {
            var             leaveRequest  = (LeaveRequest)entity;
            var             leaveResponse = new LeaveResponse();
            List <PeerBase> connections;

            if (ServerGameBaseServerPlugin.UsersInScenes.TryGetValue(leaveRequest.GameName, out connections))
            {
                var connInGame = connections.FirstOrDefault(x => x == connection.Peer);

                if (connInGame != null)
                {
                    leaveResponse.IsOk = true;
                    ServerGameBaseServerPlugin.RaiseGameLeft(connInGame);
                    connections.Remove(connInGame);
                }
                leaveResponse.OperationDetails = "User not in game";
            }
            else
            {
                leaveResponse.OperationDetails = "Game not found";
            }

            leaveResponse.ConnectionId = connection.ConnectionId;
            var cmd = BinaryProtocolHelper <LeaveResponse> .GetProtocol(leaveResponse);

            connection.SendData(cmd);

            ServerGameBaseServerPlugin.SendToGamePlayers(leaveRequest.GameName, cmd);
        }
Пример #2
0
        public void Execute <T>(ServerConnection <T> connection, IServerCommand entity)
        {
            var cmd      = (MessageRequest)entity;
            var response = new MessageResponse {
                Message = cmd.Message
            };
            var data = BinaryProtocolHelper <MessageResponse> .GetProtocol(response).Data;

            PixonicServerPlugin.LastRoomAction[cmd.RoomName] = DateTime.UtcNow;
            GameBasePlugin.ServerGameBaseServerPlugin.SendToGamePlayers(RoomName, new BinaryProtocol(data, "MessageResponse"));
        }
        private void GameServerPluginOnClientDisconnected(object sender, ServerConnectionBase connection)
        {
            var peersList = UsersInScenes.FirstOrDefault(x => x.Value.Contains(connection.Peer));

            if (!string.IsNullOrEmpty(peersList.Key))
            {
                peersList.Value?.Remove(connection.Peer);

                var leaveResponse = new LeaveResponse {
                    ConnectionId = connection.ConnectionId, IsOk = true
                };
                foreach (var peer in peersList.Value)
                {
                    var cmd = BinaryProtocolHelper <LeaveResponse> .GetProtocol(leaveResponse);

                    peer.Connections.First().Value?.SendData(cmd);
                }
            }
        }
Пример #4
0
        public void Execute <T>(ServerConnection <T> connection, IServerCommand entity)
        {
            var joinCmd = (JoinRequest)entity;

            List <PeerBase> peersList;

            if (ServerGameBaseServerPlugin.UsersInScenes.TryGetValue(joinCmd.GameName, out peersList))
            {
                if (!peersList.Contains(connection.Peer))
                {
                    peersList.Add(connection.Peer);

                    var cmd = new JoinResponse {
                        IsOk = true, ConnectionId = connection.ConnectionId
                    };
                    var response = BinaryProtocolHelper <JoinResponse> .GetProtocol(cmd);

                    connection.SendData(response);

                    ServerGameBaseServerPlugin.SendToGamePlayers(joinCmd.GameName, response);
                    ServerGameBaseServerPlugin.RaiseGameJoin(connection.Peer);
                }
            }
        }