Exemplo n.º 1
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.º 2
0
 public Data()
 {
     connection.Connect();
 }