Example #1
0
 public static void InitializeNetwork()
 {
     Console.WriteLine("Initing Packets...");
     ServerHandleData.InitializePackets();
     serverSocket.Start();
     serverSocket.BeginAcceptTcpClient(new AsyncCallback(OnClientConnect), null);
 }
Example #2
0
        public static void InitializeServer()
        {
            var startTime = GetTickCount();

            Cnsl.Info("Initializing Server", true);
            //Intializing all game data arrays
            Cnsl.Debug("Initializing Game Arrays", true);
            for (var i = 0; i < Constants.MAX_PLAYERS; i++)
            {
                ServerTcp.Client[i] = new Clients();
            }
            Cnsl.Finalize("Initializing Game Arrays");
            //Start the Networking
            Cnsl.Debug("Initializing Network", true);
            Cnsl.Debug("Initializing Status Listener", true);
            ServerHandleData.InitializePackets();
            ServerTcp.InitializeNetwork();
            ServerTcp.InitializeStatusListener();
            //Load database items
            LoadData();
            var endTime = GetTickCount();

            Cnsl.Info(@"Initialization complete. Server loaded in " + (endTime - startTime) + " ms.");
            Cnsl.Banner("   Server has started successfully \n     @ " + DateTime.UtcNow + " UTC");
            Globals.Initialized = true;
            Cnsl.Finalize("Initializing Server");
        }
Example #3
0
 private void OnReceiveData(IAsyncResult result)
 {
     try
     {
         var readbytes = myStream.EndRead(result);
         if (readbytes <= 0)
         {
             //client is not connected to the server anymore
             CloseSocket(connectionID);
             return;
         }
         var newBytes = new byte[readbytes];
         Buffer.BlockCopy(readBuff, 0, newBytes, 0, readbytes);
         ServerHandleData.HandleData(connectionID, newBytes);
         myStream.BeginRead(readBuff, 0, socket.ReceiveBufferSize, OnReceiveData, null);
     }
     catch (Exception)
     {
         CloseSocket(connectionID);
     }
 }
Example #4
0
        private void OnRecieveData(IAsyncResult result)
        {
            try
            {
                int length = Stream.EndRead(result);
                if (length <= 0)
                {
                    CloseConnection();
                    return;
                }

                byte[] newBytes = new byte[length];
                Array.Copy(recBuffer, newBytes, length);
                ServerHandleData.HandleData(connectionID, newBytes);
                Stream.BeginRead(recBuffer, 0, socket.ReceiveBufferSize, OnRecieveData, null);
            }
            catch (Exception)
            {
                CloseConnection();
                return;
            }
        }