public ValidationSystem(ServerInfo serverInfo, ClientDisconnection disconnectionHandler
                         , ClientConnection connectionHandler, ServerDataPackageProvider dataPackageProvider, ServerActions serverActions)
 {
     _serverInfo           = serverInfo;
     _disconnectionHandler = disconnectionHandler;
     _connectionHandler    = connectionHandler;
     _dataPackageProvider  = dataPackageProvider;
     _serverActions        = serverActions;
 }
示例#2
0
        public PackageProcessing(PackageQueue queue, ServerActions serverActions)
        {
            _queue         = queue;
            _actionHandler = serverActions;

            _worker         = new BackgroundWorker();
            _worker.DoWork += _worker_DoWork;
            _worker.RunWorkerAsync();
        }
        public Server(string lobbyname, int maxplayercount)
        {
            _ActionsHandler = new ServerActions();

            _serverInfo = new ServerInfo(lobbyname, maxplayercount);
            _serverInfo._communications = new List <ICommunication>();

            _listener = new TcpListener(IPAddress.Parse(SERVER_IP), 8080);
            CLientConnection(_listener);
        }
        public Core()
        {
            _game                = new Game();
            _serverInfo          = new ServerInfo();
            _dataPackageProvider = new ServerDataPackageProvider(_serverInfo, _game);
            _udpserver           = new UdpBroadcast(_serverInfo);

            _connectionHandler    = new ClientConnection(_serverInfo, _dataPackageProvider);
            _disconnectionHandler = new ClientDisconnection(_game, _serverInfo, _dataPackageProvider);

            _actionsHandler   = new ServerActions(_serverInfo, _game, _disconnectionHandler, _dataPackageProvider);
            _stateMachine     = new StateMachine(_serverInfo, _actionsHandler, _game);
            _validationSystem = new ValidationSystem(_serverInfo, _disconnectionHandler, _connectionHandler, _dataPackageProvider, _actionsHandler);
            _server           = new Server(_actionsHandler, _serverInfo, _stateMachine, _validationSystem, _disconnectionHandler);
        }
示例#5
0
    private void OnLobbyCreated(Steamworks.Result result, Steamworks.Data.Lobby lobby)
    {
        Debug.Log("Lobby creation result: " + result);

        if (result == Steamworks.Result.OK)
        {
            myLobby = lobby;

            lobby.SetData("id", Steamworks.SteamClient.SteamId.ToString());

            lobby.SetData("name", lobbyName);

            lobby.SetData("pingLocation", Steamworks.SteamNetworkingUtils.LocalPingLocation.ToString());


            // Set ourselves as a moderator
            ServerActions.Mod(Steamworks.SteamClient.SteamId);

            lobby.SetPublic();


            Debug.Log("Starting network host");

            // Shut down host before starting
            if (Mirror.NetworkClient.active)
            {
                Mirror.NetworkManager.singleton.StopClient();
            }

            if (Mirror.NetworkServer.active)
            {
                Mirror.NetworkManager.singleton.StopServer();
            }


            // Start host
            NetworkManagerCallbacks.singleton.StartHost();


            Mirror.NetworkManager.singleton.ServerChangeScene("gameplay");
        }
        else
        {
            Debug.Log("Unable to create lobby.");
        }
    }
        public Server(ServerActions actionHandler, ServerInfo serverInfo, StateMachine stateMachine,
                      ValidationSystem validationSystem, ClientDisconnection disconnectionHandler)
        {
            _stateMachine = stateMachine;
            var bwStateMachine = new BackgroundWorker();

            bwStateMachine.DoWork += (obj, ea) => _stateMachine.Start();
            bwStateMachine.RunWorkerAsync();

            _validationSystem = validationSystem;
            var bwValidationSystem = new BackgroundWorker();

            bwValidationSystem.DoWork += (obj, ea) => _validationSystem.Start();
            bwValidationSystem.RunWorkerAsync();

            _serverInfo           = serverInfo;
            _actionsHandler       = actionHandler;
            _disconnectionHandler = disconnectionHandler;

            _queue   = new PackageQueue();
            _process = new PackageProcessing(_queue, _actionsHandler);

            _listener = new TcpListener(_serverInfo.ServerIPAdress, 8080);
        }
示例#7
0
 public StateMachine(ServerInfo serverinfo, ServerActions serverActions, Game game)
 {
     _serverinfo    = serverinfo;
     _actionHandler = serverActions;
     _game          = game;
 }
    /// <summary>
    /// This is the mirror network message handler for moderator requests. It just decides what server action to perform based on what type of request it recieves
    /// </summary>
    /// <param name="conn"></param>
    /// <param name="request"></param>
    public static void FulfillModeratorRequest(Mirror.NetworkConnection conn, ClientConsole.ModeratorRequest request)
    {
        // If server can verify that the connection that sent the request is a moderator, then perform their request
        if (Config.IdPresent((((PlayerData)conn.authenticationData).id), modsPath))
        {
            if (request.id == 0)
            {
                Debug.Log("[Server] Recieved moderator request: " + ((PlayerData)conn.authenticationData).steamName + " requested to " + RequestTypeToString(request.requestType) + " " + request.name);
            }
            else
            {
                Debug.Log("[Server] Recieved moderator request: " + ((PlayerData)conn.authenticationData).steamName + " requested to " + RequestTypeToString(request.requestType) + " " + request.id);
            }



            switch (request.requestType)
            {
            case ClientConsole.ModeratorRequestType.ban:

                if (request.id == 0)
                {
                    ServerActions.Ban(request.name);
                }
                else
                {
                    ServerActions.Ban(request.id);
                }

                break;

            case ClientConsole.ModeratorRequestType.kick:

                if (request.id == 0)
                {
                    ServerActions.Kick(request.name);
                }
                else
                {
                    ServerActions.Kick(request.id);
                }

                break;

            case ClientConsole.ModeratorRequestType.mod:

                if (request.id == 0)
                {
                    ServerActions.Mod(request.name);
                }
                else
                {
                    ServerActions.Mod(request.id);
                }

                break;

            case ClientConsole.ModeratorRequestType.unban:

                if (request.id == 0)
                {
                    ServerActions.UnBan(request.name);
                }
                else
                {
                    ServerActions.UnBan(request.id);
                }

                break;

            case ClientConsole.ModeratorRequestType.unmod:

                if (request.id == 0)
                {
                    ServerActions.Unmod(request.name);
                }
                else
                {
                    ServerActions.Unmod(request.id);
                }

                break;

            default:
                break;
            }
        }
    }
示例#9
0
    private void Awake()
    {
        if (singleton == null)
        {
            singleton = this;
        }
        else
        {
            Destroy(this.gameObject);
        }


        Utilities.DontDestroyOnLoad(this.gameObject);



        // ADD MORE COMMANDS HERE

        HELP = new ConsoleCommand("help", "Shows list of console commands", "help", () =>
        {
#if UNITY_SERVER
            Debug.Log("Below is a list of commands you can use. Note some of them are just for clients and they won't do anything.");

            for (int i = 0; i < commandList.Count; i++)
            {
                ConsoleCommandBase command = commandList[i] as ConsoleCommandBase;

                Debug.Log(command.commandId + " - " + command.commandDescription + " - " + command.commandFormat);
            }
#else
            showHelp = !showHelp;
#endif
        });

        SET_FOV = new ConsoleCommand <float>("set_fov", "Sets the fov of Camera.main. use set_fov <any positive number>", "set_fov <float>", (x) =>
        {
            Camera.main.fieldOfView = x;
        });


        BAN_BY_ID = new ConsoleCommand <ulong>("ban_id", "Bans the user with the given steam id", "ban_id <ulong>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Ban(x);
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.ban, name = "", id = x
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to ban player with id: " + x);
#endif
        });

        BAN_BY_NAME = new ConsoleCommand <List <string> >("ban_name", "Bans the first found user with this steam name, be careful using this.", "ban_name <string>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Ban(JoinWithSpaces(x));
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.ban, name = JoinWithSpaces(x), id = 0
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to ban player with name: " + JoinWithSpaces(x));
#endif
        });


        MOD_BY_ID = new ConsoleCommand <ulong>("mod_id", "Adds a server moderator by steamid.", "mod_id <ulong>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Mod(x);
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.mod, name = "", id = x
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to mod player with id: " + x);
#endif
        });

        MOD_BY_NAME = new ConsoleCommand <List <string> >("mod_name", "Adds a server moderator using the first found user with this steam name, be careful using this.", "mod_name <string>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Mod(JoinWithSpaces(x));
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.mod, name = JoinWithSpaces(x), id = 0
            }, 0);

            // Ask server to mod this player
            Debug.Log("Asking server to mod player with name: " + JoinWithSpaces(x));
#endif
        });


        UNBAN_BY_ID = new ConsoleCommand <ulong>("unban_id", "UnBans the user with the given steam id", "unban_id <ulong>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.UnBan(x);
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.unban, name = "", id = x
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to unban player with id: " + x);
#endif
        });

        UNBAN_BY_NAME = new ConsoleCommand <List <string> >("unban_name", "UnBans the first found user with this steam name, be careful using this.", "unban_name <string>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.UnBan(JoinWithSpaces(x));
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.unban, name = name, id = 0
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to unban player with name: " + x);
#endif
        });


        UNMOD_BY_ID = new ConsoleCommand <ulong>("unmod_id", "Removes a server moderator by steamid.", "unmod_id <int>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.UnBan(x);
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.unmod, name = "", id = x
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to unmod player with id: " + x);
#endif
        });

        UNMOD_BY_NAME = new ConsoleCommand <List <string> >("unmod_name", "Removes a server moderator using the first found user with this steam name, be careful using this.", "unmod_name <string>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Unmod(JoinWithSpaces(x));
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.unmod, name = JoinWithSpaces(x), id = 0
            }, 0);

            // Ask server to mod this player
            Debug.Log("Asking server to unmod player with name: " + JoinWithSpaces(x));
#endif
        });


        KICK_BY_ID = new ConsoleCommand <ulong>("kick_id", "Kicks the player from the session", "kick <ulong>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Kick(x);
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.kick, name = "", id = x
            }, 0);

            // Ask server to ban this player
            Debug.Log("Asking server to kick player with id: " + x);
#endif
        });


        KICK_BY_NAME = new ConsoleCommand <List <string> >("kick_name", "Kicks the player from the session", "kick <string>", (x) =>
        {
#if UNITY_SERVER
            ServerActions.Kick(JoinWithSpaces(x));
#else
            Mirror.NetworkClient.Send(new ModeratorRequest {
                requestType = ModeratorRequestType.kick, name = JoinWithSpaces(x), id = 0
            }, 0);

            Debug.Log("Asking server to kick player with name: " + JoinWithSpaces(x));
#endif
        });


        SET_FOV = new ConsoleCommand <float>("set_fov", "Sets the fov of Camera.main. use set_fov <any positive number>", "set_fov <float>", (x) =>
        {
            Camera.main.fieldOfView = x;
        });



        // Takes a list of strings and concatinates them into one string connected with spaces
        string JoinWithSpaces(List <string> x)
        {
            string name = "";

            for (int i = 0; i < x.Count; i++)
            {
                name += x[i];

                if (i < x.Count - 1)
                {
                    name += " ";
                }
            }

            Debug.Log("JoinWithSpaces() returned: " + name);

            return(name);
        }

        // Prepend server only commands with #if UNITY_SERVER so that they don't get put into client builds at all
#if UNITY_SERVER
        SERVER_DEBUG_MESSAGE = new ConsoleCommand <string>("debug", "Debug.logs a message on the server's client only", "debug <string>", (x) =>
        {
            Debug.Log(x);
        });
#endif

        // ADD MORE COMMANDS HERE



        commandList = new List <object>
        {
            SET_FOV,
            HELP,
            BAN_BY_NAME,
            BAN_BY_ID,
            MOD_BY_ID,
            MOD_BY_NAME,
            KICK_BY_ID,
            KICK_BY_NAME,
            UNBAN_BY_ID,
            UNMOD_BY_ID,
            UNBAN_BY_NAME,
            UNMOD_BY_NAME,



#if UNITY_SERVER
            SERVER_DEBUG_MESSAGE,
#endif
        };
    }