Exemplo n.º 1
0
        private static void handleLogin(Client c, string message)
        {
            EClientStatus status = c.getCurrentStatus();

            if (status == EClientStatus.Guest)
            {
                if (message == "r")
                {
                    s.sendMessageToClient(c, Server.END_LINE + "Password: "******"r")
                {
                    s.clearClientScreen(c);
                    s.sendMessageToClient(c, "Successfully authenticated." + Server.END_LINE + Server.CURSOR);
                    c.setStatus(EClientStatus.LoggedIn);
                }

                else
                {
                    s.kickClient(c);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Client"/> class.
 /// </summary>
 /// <param name="clientId">The client's identifier.</param>
 /// <param name="remoteAddress">The remote address.</param>
 public Client(uint clientId, IPEndPoint remoteAddress)
 {
     this.id           = clientId;
     this.remoteAddr   = remoteAddress;
     this.connectedAt  = DateTime.Now;
     this.status       = EClientStatus.Guest;
     this.receivedData = string.Empty;
 }
Exemplo n.º 3
0
        private static void messageReceived(Client c, string message)
        {
            Console.WriteLine("MESSAGE: " + message);

            if (message.ToLower() != "quit")
            {
                EClientStatus status = c.GetCurrentStatus();

                switch (c.GetCurrentStatus())
                {
                case EClientStatus.Login:
                    //TODO:帳號驗證 Default:nono
                    if (message == "nono")
                    {
                        s.SendMessageToClient(c, "\r\nPassword: "******"\r\n帳號錯誤,請重新輸入!!\r\nLogin:"******"nono")
                    {
                        s.SendMessageToClient(c, "\r\n登入成功\r\n");
                        c.SetStatus(EClientStatus.LoggedIn);
                    }
                    else
                    {
                        s.SendMessageToClient(c, "\r\n密碼錯誤,請重新輸入!!\r\nPassword:"******"\r\n你打啥我看不懂?!\r\n > ");
                    break;
                }
            }
            else
            {
                s.KickClient(c);
            }
        }
Exemplo n.º 4
0
        ////////////////////////////////////////////////////////////////////////////////////

        public UnityClient(Client2 client = null, float clockRatePerSecond = 2f)
        {
            this.client = client;
            this.status = EClientStatus.NEW;
            this.id     = ID_COUNTER++;

            if (client != null)
            {
                client.OnReceivedBytes += OnClientReceivedBytes;
            }

            _messageQueueIn   = new MessageQueue2();
            _messageQueueOut  = new MessageQueue2();
            _messageDiscarded = new List <Message2>();

            //If the internal clock isn't required, anything below zero won't initialize it:
            if (clockRatePerSecond < 0)
            {
                return;
            }

            //Add a client-side Master-Clock / ticker:
            clockTicker = new Clockwork().StartAutoUpdate(clockRatePerSecond);

            //Add a gear to periodically check the incoming and outgoing messages:
            clockTicker.AddGear()
            .AddListener(__ProcessMessage)
            .SetParams(timeMode: EGearTimeMode.FRAME_BASED);

            //Add a gear to send a "heartbeat" packet to the server, basically a *keep-alive* signal:
            clockTicker.AddGear("HeartBeat")
            .AddListener(__HeartBeat)
            .SetParams(counterReset: 1, timeMode: EGearTimeMode.TIME_BASED);

            //clockTicker.AddInterleaving(OnSendPosition, OnSendRotation);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Sets the client's current status.
 /// </summary>
 /// <param name="newStatus">The new status.</param>
 public void SetStatus(EClientStatus newStatus)
 {
     this.status = newStatus;
 }
Exemplo n.º 6
0
 /// <summary>Erzeugt den Clienten für den Clienten
 /// </summary>
 public Client()
 {
     this.clientStatus = EClientStatus.Connected;
 }
Exemplo n.º 7
0
 /// <summary>Erzegt einen Clienten für den Server
 /// <para>IPEndPoint _IPEndPoint</para>
 /// </summary>
 public Client(IPEndPoint _IPEndPoint)
 {
     this.iPEndPoint = _IPEndPoint;
     this.clientStatus = EClientStatus.Connected;
 }
Exemplo n.º 8
0
 /// <summary>Erzeugt den Clienten für den Clienten
 /// </summary>
 public Client()
 {
     this.clientStatus = EClientStatus.Connected;
 }
Exemplo n.º 9
0
 /// <summary>Erzegt einen Clienten für den Server
 /// <para>IPEndPoint _IPEndPoint</para>
 /// </summary>
 public Client(IPEndPoint _IPEndPoint)
 {
     this.iPEndPoint   = _IPEndPoint;
     this.clientStatus = EClientStatus.Connected;
 }
Exemplo n.º 10
0
        private static void messageReceived(Client c, string message)
        {
            PluginLog(Log.Level.Debug, "MESSAGE: " + message);
            EClientStatus status = c.getCurrentStatus();

            if (message == "quit")
            {
                s.kickClient(c);
                return;
            }
            if (message == "help")
            {
                s.sendMessageToClient(c, "\r\n" + Resources.help + "\r\n");
                return;
            }
            if (message.StartsWith("help "))
            {
                var helpcmd = message.Replace("help ", "");
                s.sendMessageToClient(c, "\r\nerror id=1337 msg=currently\\snot\\simplemented\r\n");
                //s.sendMessageToClient(c, Resources[helpcmd]);
                return;
            }
            switch (status)
            {
            case EClientStatus.Guest:
                if (message == "auth apikey=" + Settings.Default.ApiKey)
                {
                    s.clearClientScreen(c);
                    s.sendMessageToClient(c, "\r\nerror id=0 msg=ok\r\n");
                    c.setStatus(EClientStatus.LoggedIn);
                    return;
                }
                else
                {
                    s.sendMessageToClient(c, "\r\nerror id=1796 msg=currently\\snot\\spossible\r\n");
                    return;
                }

            case EClientStatus.LoggedIn:
                if (message == "logout")
                {
                    c.setStatus(EClientStatus.Guest);
                    s.sendMessageToClient(c, "\r\nerror id=0 msg=ok\r\n");
                    return;
                }
                break;
            }
            if (message.StartsWith("gm msg="))
            {
                try {
                    lib.SendGlobalMessage(message.Replace("gm msg=", ""));
                    s.sendMessageToClient(c, "\r\nerror id=0 msg=ok\r\n");
                } catch (Exception) {
                    s.sendMessageToClient(c, "\r\nerror id=1 msg=error\r\n");
                }
                return;
            }
            switch (message)
            {
            default:
                s.sendMessageToClient(c, "\r\nerror id=256 msg=command\\snot\\sfound\r\n");
                return;
            }
        }
Exemplo n.º 11
0
 public bool HasStatus(EClientStatus whichStatus)
 {
     return((status & whichStatus) > 0);
 }