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 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);
                }
            }
        }