Beispiel #1
0
 public Server(Configuration configuration)
 {
     config       = configuration;
     input        = new Demultiplexer(config.maxPacketsInQueue);
     joins        = new Dictionary <string, Packet>();
     ghost        = new GameObject("Server Ghost");
     lagSimulator = new LagSimulator(config);
     local        = new Link.Builder()
                    .Bind(true)
                    .IP("0.0.0.0")
                    .Port(config.serverListeningPort)
                    .ReceiveTimeout(config.serverReceiveTimeout)
                    .SendTimeout(config.serverSendTimeout)
                    .Build();
     links    = new List <Link>();
     outputs  = new List <Stream>();
     snapshot = config.GetServerSnapshot();
     acks     = new SortedDictionary <int, Packet> [config.maxPlayers];
     for (int i = 0; i < config.maxPlayers; ++i)
     {
         acks[i] = new SortedDictionary <int, Packet>();
     }
     threading      = new Threading();
     ghostTransform = ghost.transform;
     world          = GameObject.Find("World")
                      .GetComponent <World>()
                      .LoadSnapshot(snapshot);
     lastSnapshot = 0.0f;
     timestamp    = 0.0f;
 }
Beispiel #2
0
 /**
  * Aplica round-robin: para cada stream de salida, si hay algún paquete lo
  * envía y continúa con el siguiente stream.
  */
 protected void ResponseHandler()
 {
     System.Random   random        = new System.Random();
     LagSimulator [] lagSimulators = new LagSimulator [config.maxPlayers];
     Debug.Log("Loading " + lagSimulators.Length + " lag simulators for response.");
     for (int k = 0; k < lagSimulators.Length; ++k)
     {
         lagSimulators[k] = new LagSimulator(config);
     }
     while (!config.OnExit())
     {
         for (int id = 0; id < outputs.Count; ++id)
         {
             Packet packet = outputs[id].Read();
             if (packet != null && config.packetLossRatio <= random.NextDouble())
             {
                 lagSimulators[id].Write(packet, timestamp);
             }
         }
         for (int id = 0; id < outputs.Count; ++id)
         {
             Packet futurePacket = lagSimulators[id].Read(timestamp);
             if (futurePacket != null)
             {
                 local.Send(links[id], futurePacket);
             }
         }
     }
 }