コード例 #1
0
        static void HandleDataReceived(ServerConnection sender, DataEventArgs e)
        {
            /*
            Interlocked.Increment(ref currencies);

            byte[] temp = new byte[] { 0xAA, 0xBB, 0x00, 0x09, 0xA0, 0x0A, 0x00, 0x00, 0x00 };

            sender.SendData(temp, 0, temp.Length);

            return;
            */

            /**/

            byte[] datas = e.Data;
            Interlocked.Increment(ref messages);
            Interlocked.Add(ref bytes, datas.Length);

            var msg = Message.ConvertFrom(datas);
            //var line = e.Data.ToHexString();
            //File.AppendAllText("data.txt", line + Environment.NewLine);
            if (msg == null)
            {
                return;
            }

            if (msg.Datas == null)
            {
                msg.Datas = new byte[] { 0 };
            }

            byte flag = 0;

            if (msg.Type == (int)MessageType.Beep)
            {
                UpdateDeviceInfo(msg, e.Device);
            }

            else if (msg.Type == (int)MessageType.Login)
            {
                if (msg.Device == null)
                {
                    ServerInstrumentation.Current.LoginFailed();

                    if (!allowAllowAnonymous)
                    {
                        flag = 1;
                        sender.Disconnect();
                        return;
                    }
                }

                if (!allowAllowAnonymous || msg.Device != null)
                {
                    UpdateDeviceInfo(msg, e.Device);
                    sender.AuthorizationType = AuthorizationType.Authorized;
                }
            }

            else if (msg.Type == (int)MessageType.Detail)
            {
                Interlocked.Increment(ref currencies);

                if (!allowAllowAnonymous && sender.AuthorizationType == AuthorizationType.Anonymous)
                {
                    ServerInstrumentation.Current.Unregisted();

                    if (!allowAllowAnonymous)
                    {
                        sender.Disconnect();
                        return;
                    }
                }
                UpdateDeviceInfo(msg, e.Device);
                e.Device.Increate();
                if (msg.Currency != null)
                {
                    DataPool.Push(msg.Currency);
                }
            }

            else if (msg.Type == (int)MessageType.BlackTable)
            {

            }

            else if (msg.Type == (int)MessageType.DownLoadBlackTable)
            {

            }

            var data = msg.GetBytes(flag);
            sender.SendData(data, 0, data.Length);
        }
コード例 #2
0
 static void DataReceived(ServerConnection sender, DataEventArgs e)
 {
     try
     {
         HandleDataReceived(sender, e);
     }
     catch (Exception ex)
     {
         ElibExceptionHandler.Handle(ex as Exception);
     }
 }