Exemplo n.º 1
0
    public static void Stop()
    {
        Development.Log("Stopping Server");

        if (TcpReady)
        {
            Development.Log("Shutting Down TCP Listener");
            tcpListener.Stop();
            tcpListener = null;
        }

        if (UdpReady)
        {
            Development.Log("Shutting Down UDP Listener");
            udpListener.Close();
            udpListener = null;
        }


        if (PacketsReady)
        {
            Development.Log("Clearing Packet Receivers");
            packetReceivers.Clear();
            packetReceivers = null;
        }

        if (ClientsReady)
        {
            // Setup Max Clients
            Development.Log("Clearing Client Connections");
            clients.Clear();
        }

        if (DatabaseReady)
        {
            Game.Save();
            Development.Log("Disconnected from MySQL");
            database.Disconnect();
            database = null;
        }

        Development.Log("Server Shutdown");
        IsReady = false;
        Development.Divider();
    }
Exemplo n.º 2
0
    private static void InitializeServerData()
    {
        // Connect to MySQL
        Development.Log("Connecting to MySQL");
        if (!database.Connect())
        {
            Debug.LogError("No Database Connection... Shutting Down");
            return;
        }

        // Setup Max Clients
        Development.Log("Initializing Client Connections");
        for (int i = 1; i <= MaxPlayers; i++)
        {
            clients.Add(i, new Client(i));
        }

        // Init Packet Receivers.
        Development.Log("Initializing Packet Receivers");
        InitPacketReceiver(Client.Packets.Welcome, Receive.Welcome);
        InitPacketReceiver(Client.Packets.PlayerMovement, Receive.PlayerMovement);
        InitPacketReceiver(Client.Packets.PlayerShoot, Receive.PlayerShoot);
        InitPacketReceiver(Client.Packets.PlayerThrowItem, Receive.PlayerThrowItem);
        InitPacketReceiver(Client.Packets.PlayerInspect, Receive.PlayerThrowItem);
        InitPacketReceiver(Client.Packets.Registration, Receive.Registration);

        // Startup TCP Listener
        Development.Log("Starting TCP Listener");
        tcpListener = new TcpListener(IPAddress.Any, Port);
        tcpListener.Start();
        tcpListener.BeginAcceptTcpClient(TCPConnectCallback, null);

        // Startup UDP Listener
        Development.Log("Starting UDP Listener");
        udpListener = new UdpClient(Port);
        udpListener.BeginReceive(UDPReceiveCallback, null);

        Development.Log($"Server Started ( {Port} )");
        IsReady = true;

        // Delegate to a new Game()
        Game.Load();
    }
Exemplo n.º 3
0
    public static void Start(int _maxPlayers, int _port)
    {
        Util.IniFile MyIni   = new Util.IniFile("Settings.ini");
        string       section = "MySQL";
        string       host    = MyIni.Read("Host", section);
        string       user    = MyIni.Read("Username", section);
        string       pass    = MyIni.Read("Password", section);
        string       db      = MyIni.Read("Database", section);

        database = new Database.Connection(host, db, user, pass, true);
        Development.Log("Starting Server");

        MaxPlayers = _maxPlayers;
        Port       = _port;

        // Setup Server Packets
        InitializeServerData();

        Development.Divider();
    }