Exemplo n.º 1
0
 public SplitThread(int index, UDPClient udpClient, int baseMsgID)
 {
     this.msgID = baseMsgID;
     this.index = index;
     this.udpClient = udpClient;
     innerThread = new Thread(new ThreadStart(distribute));
     innerThread.Start();
     Thread.Sleep(5);
 }
Exemplo n.º 2
0
 // initialization method
 public void Initialize(int posX, int posY, int HPStatus, int APStatus)
 {
     m_posX = posX;
     m_posY = posY;
     m_HP = HPStatus;
     m_AP = APStatus;
     boxCollider = GetComponent<BoxCollider2D>();
     if (boardManager == null)
     {
         boardManager = GameObject.Find("BoardManager").GetComponent<BoardManager>();
     }
     if (client == null)
     {
         client = boardManager.GetComponent<UDPClient>();
     }
     transform.position = new Vector3(posX, posY, 0);
 }
Exemplo n.º 3
0
 public override void init(MsgConsumer consumer)
 {
     for (int i = 0; i < serverCount;i++ )
     {
         udpServers[i] = new UDPServer(local[i], this);
     }
     for (int i=0; i< clientCount;i++)
     {
         udpClients[i] = new UDPClient(remote[i]);
     }
     if (clientCount > 1)
     {
         deliveryThreads = new SplitThread[clientCount];
         for (int i=0; i < clientCount; i++)
         {
             deliveryThreads[i] = new SplitThread(i, udpClients[i], msgID);
         }
     }
     base.init(consumer);
 }
Exemplo n.º 4
0
        public AuthServer()
        {
            _packetLogger = new PacketLogger();
            _logger = new Logger() { WriteToConsole = true };
            _logger.Load(Path.Combine("logs", string.Format("auth_{0}.log", DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss"))));
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                Error(s, new ExceptionEventArgs((Exception)e.ExceptionObject));
                Environment.Exit(0);
            };

            _packetLogger.Load("auth_packets.log");
            _logger.Info("Loaded Packet Logger");

            Stopwatch sw = Stopwatch.StartNew();
            AuthConfig.Load();
            sw.Stop();
            _logger.Info("Loaded Auth Configuration in {0} ms", sw.Elapsed.TotalMilliseconds);

            _logger.Info("Starting up server connections...");

            _server = new TcpServer(IPAddress.Parse(AuthConfig.Instance.IP), AuthConfig.Instance.Port);
            _server.PacketReceived += HandlePacket;
            _server.Error += Error;

            //
            // Initalize a list of ports
            //

            ushort[] ports = { 38915, 38917 };

            for (uint i = 0; ports.Length > i; i++ )
            {
                // Handle NAT tests before starting...
                switch (i)
                {
                    case 0:
                        _natServer = new UDPClient(ports[0]);
                        _natServer.PacketReceived += HandleNATTest;
                        _natServer.Error += Error;
                        _logger.InfoAuth("NAT Test successful at Port {0}", ports[0]);
                        break;
                    case 1:
                        _natServer2 = new UDPClient(ports[1]);
                        _natServer2.PacketReceived += HandleNATTest2;
                        _natServer2.Error += Error;
                        _logger.InfoAuth("NAT Test successful at Port {0}", ports[1]);
                        break;
                    default:
                        break;
                }
            }

            // Bind to pipe/tcp/http settings in configuration
            var isMono = Type.GetType("Mono.Runtime") != null;
            switch (AuthConfig.Instance.Remote.Binding)
            {
                case "pipe":
                    if (isMono)
                    {
                        _logger.Error("pipe is not supported in mono, use http!");
                        Environment.Exit(1);
                        return;
                    }
                    _remoteServer = new RemoteServer(this, ERemoteBinding.Pipe, string.Format("localhost/AuthServer/{0}/", SHA256.ComputeHash(AuthConfig.Instance.Remote.Password)));
                    break;

                case "tcp":
                    if (isMono)
                    {
                        _logger.Error("tcp is not supported in mono, use http!");
                        Environment.Exit(1);
                        return;
                    }
                    _remoteServer = new RemoteServer(this, ERemoteBinding.Pipe, string.Format("{0}:{1}/AuthServer/{2}/", AuthConfig.Instance.Remote.Server, AuthConfig.Instance.Remote.Port, SHA256.ComputeHash(AuthConfig.Instance.Remote.Password)));
                    break;

                case "http":
                    _remoteServer = new RemoteServer(this, ERemoteBinding.Http, string.Format("{0}:{1}/AuthServer/{2}/", AuthConfig.Instance.Remote.Server, AuthConfig.Instance.Remote.Port, SHA256.ComputeHash(AuthConfig.Instance.Remote.Password)));
                    break;

                default:
                    _logger.Error("Invalid remote binding '{0}'", AuthConfig.Instance.Remote.Binding);
                    Environment.Exit(1);
                    return;
            }
            _remoteServer.AddServiceEndpoint(typeof(IAuthRemote), "IAuthRemote");
        }