Пример #1
0
        protected override void OnMessage(MessageEventArgs yevent)
        {
            YingYing.getYConsole().sendYMessage("颖: " + yevent.Data);

            try
            {
                YingStruct ymessage = LitJson.JsonMapper.ToObject <YingStruct>(yevent.Data);

                if (ymessage.Ying == "颖")
                {
                    /*switch (ymessage.YType)
                     * {
                     *  case YingStruct.YingType.Ying:
                     *      SendAsync(JsonMapper.ToJson(new YingStruct()
                     *      {
                     *          YType = YingStruct.YingType.Ying,
                     *          YData = new YingStruct.YingData()
                     *          {
                     *              ycode = 0,
                     *              ysender = "YingServer",
                     *              ymessage = JsonMapper.ToJson(new iYingStruct()
                     *              {
                     *                  yservername = "Ying Server Air Plus",
                     *                  yipaddress = "127.0.0.1",
                     *                  ymotd = "so tell me your story."
                     *              }),
                     *              ydata = null
                     *          }
                     *      }), ycompleted);
                     *      break;
                     *
                     *  case YingStruct.YingType.YUpdata:
                     *      SendAsync(JsonMapper.ToJson(new YingStruct()
                     *      {
                     *          YType = YingStruct.YingType.YUpdata,
                     *          YData = new YingStruct.YingData()
                     *          {
                     *              ycode = 0,
                     *              ysender = "YingServer",
                     *              //ymessage = JsonMapper.ToJson(YingWindow.yy),
                     *              ydata = null
                     *          }
                     *      }), ycompleted);
                     *
                     *      SendAsync(new System.IO.FileInfo(@"Z:\Ying\YingServer\Ying\Ying\YingApp.xaml.cs"), ycompleted);
                     *
                     *
                     *      break;
                     *
                     *  case YingStruct.YingType.YLogin:
                     *      SendAsync(JsonMapper.ToJson(new YingStruct()
                     *      {
                     *          YType = YingStruct.YingType.YLogin,
                     *          YData = new YingStruct.YingData()
                     *          {
                     *              ycode = 0,
                     *              ysender = "YingServer",
                     *              ymessage = "Login Success",
                     *              ydata = null
                     *          }
                     *      }), ycompleted);
                     *      break;
                     *
                     *  case YingStruct.YingType.YMessage:
                     *      YingYing.getYServer().getYService().BroadcastAsync(yevent.Data, () => { });
                     *      break;
                     *
                     *  default:
                     *      break;
                     * }*/
                }
                else
                {
                    SendAsync(JsonMapper.ToJson(new YingStruct()
                    {
                        ytype = YingStruct.YingType.Ying,
                        ydata = new YingStruct.YingData()
                        {
                            ycode    = 1,
                            ysender  = "YingServer",
                            ymessage = "Wrong package",
                            ydata    = null
                        }
                    }), ycompleted);
                }

                /*/
                 *  YingYing.getYEvent().Subscribe<PayloadEvent<YingStruct>>((y) =>
                 *  {
                 *
                 *  });
                 *
                 *
                 *  YingYing.getYEvent().Publish(new PayloadEvent<YingUpdataStruct>(new YingUpdataStruct()
                 *  {
                 *      YUpdata = new Dictionary<String, Object> {
                 *          { "ydata" ,null },
                 *          { "yurl" , null }
                 *      }
                 *  }));
                 * /*/
            }
            catch (Exception yexception)
            {
                YingYing.getYConsole().sendYMessage("Recived a wrong package. Its content is " + yevent.Data);
                YingYing.getYConsole().sendYMessage(yexception.Message + Environment.NewLine + yexception.StackTrace);
            }


            /*JObject ymessage = (JObject)JsonConvert.DeserializeObject(yevent.Data);
             * if (ymessage["Ying"].ToString() == "颖") {
             *  if (ymessage.ContainsKey("YUpdata")) {
             *      /*Dictionary<String, Object> y = new Dictionary<String, Object>();
             *      y.Add("Ying", "颖");
             *      Dictionary<String, String> yy = new Dictionary<String, String>();
             *      yy.Add("ydata", YingWindow.yy);
             *      yy.Add("yurl", "http://222.136.107.157:60408/yclient/");
             *      y.Add("YUpdata", yy);*/
            /*SendAsync(JsonConvert.SerializeObject(new YingStruct() {
             *  YUpdata = new Dictionary<String, Object> {
             *      {"ydata", YingWindow.yy}, {"yurl", "http://222.136.107.157:60408/yclient/"}
             *  }
             * }), null);*//*
             *
             * }
             * }
             * else
             * {
             * //Sessions.CloseSession(yevent.);
             * }*/
            //{"Ying": "颖", "YUpdata": "Ying"}
        }
Пример #2
0
        public YingBehavior()
        {
            yclient.OnOpen += (sender, yevent) =>
            {
                Console.WriteLine("YingOpen");
            };

            yclient.OnMessage += (sender, yevent) =>
            {
                Console.WriteLine("颖: " + yevent.Data);

                YingStruct ymessage = JsonConvert.DeserializeObject <YingStruct>(yevent.Data);
                if (ymessage.Ying != "颖")
                {
                    return;
                }
                switch (ymessage.ytype)
                {
                case YingStruct.YingType.Ying:
                    /*yclient.SendAsync(JsonConvert.SerializeObject(new YingStruct()
                     * {
                     *  ytype = YingStruct.YingType.Ying,
                     *  ydata = new YingStruct.YingData()
                     *  {
                     *      ycode = 0,
                     *      ysender = "Ying Server",
                     *      ymessage = JsonConvert.SerializeObject(new iYingStruct()
                     *      {
                     *          yservername = "Ying Server Air Plus",
                     *          yipaddress = "127.0.0.1",
                     *          ymotd = "so tell me your story."
                     *      }),
                     *      ydata = null
                     *  }
                     * }), ycompleted);*/
                    break;

                case YingStruct.YingType.YUpdata:
                    /*this.SendAsync(JsonConvert.SerializeObject(new YingStruct()
                     * {
                     *   ytype = YingStruct.YingType.YUpdata,
                     *   ydata = new YingStruct.YingData()
                     *   {
                     *       ycode = 0,
                     *       ysender = "Ying Server",
                     *       ymessage = JsonConvert.SerializeObject(new YingUpdataStruct
                     *       {
                     *       }),
                     *       ydata = null
                     *   }
                     * }), ycompleted);*/
                    break;

                case YingStruct.YingType.YLogin:

                    YingLoginStruct ylogin = JsonConvert.DeserializeObject <YingLoginStruct>(ymessage.ydata.ymessage);
                    getYEvent().Publish <YingLoginEvent>(new YingLoginEvent {
                        isYSuccess = ylogin.yaccessToken != null,
                        ymessage   = ylogin.ymessage
                    });
                    getYEvent().Publish <YingPackageEvent>(new YingPackageEvent
                    {
                        isYSend = false,
                        yStruct = ymessage
                    });

                    break;

                case YingStruct.YingType.YCode:
                    getYEvent().Publish <YingPackageEvent>(new YingPackageEvent
                    {
                        isYSend = false,
                        yStruct = ymessage
                    });

                    break;

                case YingStruct.YingType.YRegister:
                    getYEvent().Publish <YingPackageEvent>(new YingPackageEvent
                    {
                        isYSend = false,
                        yStruct = ymessage
                    });

                    break;

                case YingStruct.YingType.YMessage:
                    //this.SendAsync(yevent.Data, ycompleted);
                    break;

                case YingStruct.YingType.YMusic:
                    //this.SendAsync(yevent.Data, ycompleted);
                    break;

                default:
                    break;
                }
            };

            yclient.OnClose += (sender, yevent) =>
            {
                Console.WriteLine("YingClose");
            };

            yclient.OnError += (sender, yevent) =>
            {
                Console.WriteLine("YingError");
            };

            getYEvent().Subscribe <YingPackageEvent>((yevent) => {
                if (!yevent.isYSend)
                {
                    return;
                }
                if (yclient.IsAlive)
                {
                    yclient.SendAsync(JsonConvert.SerializeObject(yevent.yStruct), this.ycompleted);
                }
            });

            ytimer.Tick += (ysender, yevent) =>
            {
                try
                {
                    if (!yclient.IsAlive)
                    {
                        yclient.ConnectAsync();
                    }
                }
                catch (Exception yexception)
                {
                    YingMessageBox.Ying($"Ying: {yexception.Message}", YingMessageBox.YingMessageType.yface_cry, 6040);
                }
            };
        }
Пример #3
0
        protected override void OnMessage(MessageEventArgs yevent)
        {
            YingStruct ymessage = JsonConvert.DeserializeObject <YingStruct>(yevent.Data);

            if (ymessage.Ying != "颖")
            {
                return;
            }
            switch (ymessage.ytype)
            {
            case YingStruct.YingType.Ying:
                this.SendAsync(JsonConvert.SerializeObject(new YingStruct()
                {
                    ytype = YingStruct.YingType.Ying,
                    ydata = new YingStruct.YingData()
                    {
                        ycode    = 0,
                        ysender  = "Ying Server",
                        ymessage = JsonConvert.SerializeObject(new iYingStruct()
                        {
                            yservername = "Ying Server Air Plus",
                            yipaddress  = "127.0.0.1",
                            ymotd       = "so tell me your story."
                        }),
                        ydata = null
                    }
                }), ycompleted);
                break;

            case YingStruct.YingType.YUpdata:
                this.SendAsync(JsonConvert.SerializeObject(new YingStruct()
                {
                    ytype = YingStruct.YingType.YUpdata,
                    ydata = new YingStruct.YingData()
                    {
                        ycode    = 0,
                        ysender  = "Ying Server",
                        ymessage = JsonConvert.SerializeObject(new YingUpdataStruct
                        {
                        }),
                        ydata = null
                    }
                }), ycompleted);
                break;

            case YingStruct.YingType.YLogin:

                YingLoginStruct        ylogin  = JsonConvert.DeserializeObject <YingLoginStruct>(ymessage.ydata.ymessage);
                YingAuthenticateResult yresult = YingAuthenticate.yauthenticate(ylogin.yuser.yemail, ylogin.yuser.ypassword);
                YingLoginStruct        yylogin = new YingLoginStruct();
                if (ylogin.yclientToken == null)
                {
                    ylogin.yclientToken = Guid.NewGuid().ToString("N");
                }

                if (yresult.ysuccess)
                {
                    String yaccessToken = Guid.NewGuid().ToString("N");
                    getYDataBaseManager().getYConnection().Insert(new zyy_yggdrasil_tokens
                    {
                        yemail = ylogin.yuser.yemail,

                        yclientToken = ylogin.yclientToken,
                        yaccessToken = yaccessToken,

                        ytime = getYTimeStamp().TotalMilliseconds
                    });

                    zyy_users yuser = yresult.yuser;
                    yuser.ypassword = null;
                    yuser.ysalt     = null;

                    yylogin = new YingLoginStruct
                    {
                        yclientToken = ylogin.yclientToken,
                        yaccessToken = yaccessToken,
                        ymessage     = "Ying Ok",
                        yuser        = yuser
                    };
                }
                else
                {
                    yylogin = new YingLoginStruct
                    {
                        yclientToken = ylogin.yclientToken,
                        yaccessToken = null,
                        ymessage     = "Ying Error"
                    };
                }

                this.SendAsync(JsonConvert.SerializeObject(new YingStruct()
                {
                    Ying  = "颖",
                    ytype = YingStruct.YingType.YLogin,
                    ydata = new YingStruct.YingData()
                    {
                        ycode    = 0,
                        ysender  = "Ying Server",
                        ymessage = JsonConvert.SerializeObject(yylogin),
                        ydata    = null
                    }
                }), ycompleted);
                break;

            case YingStruct.YingType.YCode:
                YingCodeStruct ycode = JsonConvert.DeserializeObject <YingCodeStruct>(ymessage.ydata.ymessage);
                if (ycode.ycode == 20020604)
                {
                    if (YingAuthenticate.yauthenticate(ycode.yemail, String.Empty).yuser.yid == 0)
                    {
                        int yycode = new Random().Next(100000, 1000000);
                        try
                        {
                            getYDataBaseManager().getYConnection().Delete <zyy_verification_code>((from y in getYDataBaseManager().getYConnection().Table <zyy_verification_code>()
                                                                                                   where y.yemail == ycode.yemail
                                                                                                   select y).FirstOrDefault().yid);
                        }
                        catch { }
                        getYDataBaseManager().getYConnection().Insert(new zyy_verification_code
                        {
                            yemail = ycode.yemail,
                            ycode  = yycode,
                            ytime  = getYTimeStamp().TotalMilliseconds
                        });
                        YingMail.ysend(ycode.yemail, new System.IO.StreamReader(getYFiles().getYResource("Ying.yresources.yhtml.Ying.html")).ReadToEnd().Replace("{{yname}}", "烟雨城").Replace("{{ycode}}", Convert.ToString(yycode)));
                        ycode.isYSuccess = true;
                        ycode.ymessage   = "验证码已发送到您的邮箱";
                        this.SendAsync(JsonConvert.SerializeObject(new YingStruct()
                        {
                            Ying  = "颖",
                            ytype = YingStruct.YingType.YCode,
                            ydata = new YingStruct.YingData()
                            {
                                ycode    = 0,
                                ysender  = "Ying Server",
                                ymessage = JsonConvert.SerializeObject(ycode),
                                ydata    = null
                            }
                        }), ycompleted);
                    }
                    else
                    {
                        ycode.isYSuccess = false;
                        ycode.ymessage   = "该邮箱地址已经被使用";
                        this.SendAsync(JsonConvert.SerializeObject(new YingStruct()
                        {
                            Ying  = "颖",
                            ytype = YingStruct.YingType.YCode,
                            ydata = new YingStruct.YingData()
                            {
                                ycode    = 0,
                                ysender  = "Ying Server",
                                ymessage = JsonConvert.SerializeObject(ycode),
                                ydata    = null
                            }
                        }), ycompleted);
                    }
                }
                else
                {
                    zyy_verification_code yycode = (from y in getYDataBaseManager().getYConnection().Table <zyy_verification_code>()
                                                    where y.yemail == ycode.yemail
                                                    select y).FirstOrDefault();
                    if (ycode.ycode == yycode.ycode)
                    {
                        ycode.isYSuccess = true;
                        ycode.ymessage   = "验证码正确";
                    }
                    else
                    {
                        ycode.isYSuccess = false;
                        ycode.ymessage   = "验证码错误";
                    }
                    this.SendAsync(JsonConvert.SerializeObject(new YingStruct()
                    {
                        Ying  = "颖",
                        ytype = YingStruct.YingType.YCode,
                        ydata = new YingStruct.YingData()
                        {
                            ycode    = 0,
                            ysender  = "Ying Server",
                            ymessage = JsonConvert.SerializeObject(ycode),
                            ydata    = null
                        }
                    }), ycompleted);
                }
                break;

            case YingStruct.YingType.YRegister:
                YingRegisterStruct yregister = JsonConvert.DeserializeObject <YingRegisterStruct>(ymessage.ydata.ymessage);
                if ((from y in getYDataBaseManager().getYConnection().Table <zyy_verification_code>()
                     where y.yemail == yregister.yuser.yemail
                     select y).FirstOrDefault().ycode == yregister.ycode)
                {
                    String ypassword = BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(yregister.yuser.ypassword))).Replace("-", "").ToLower();
                    String ysalt     = new YingCode(6).YCode;
                    getYDataBaseManager().getYConnection().Insert(new zyy_users {
                        yusername = yregister.yuser.yusername,
                        ypassword = BitConverter.ToString(new MD5CryptoServiceProvider().ComputeHash(Encoding.UTF8.GetBytes(ypassword + ysalt))).Replace("-", "").ToLower(),
                        ysalt     = ysalt,
                        yopenid   = Guid.NewGuid().ToString("N"),
                        ysex      = yregister.yuser.ysex,
                        yemail    = yregister.yuser.yemail,
                        yprofiles = JsonConvert.SerializeObject(new String[] { new YingUUID(yregister.yuser.yusername).YUUID.ToString("N") })
                    });
                    getYDataBaseManager().getYConnection().Insert(new zyy_yggdrasil_profile
                    {
                        yyid       = new YingUUID(yregister.yuser.yusername).YUUID.ToString("N"),
                        yname      = yregister.yuser.yusername,
                        ytextureid = "zyy2a2a1399140968341fdedc4aa8b94"
                    });
                    if (yregister.yclientToken == null)
                    {
                        yregister.yclientToken = Guid.NewGuid().ToString("N");
                    }
                    String yaccessToken = Guid.NewGuid().ToString("N");
                    getYDataBaseManager().getYConnection().Insert(new zyy_yggdrasil_tokens
                    {
                        yemail = yregister.yuser.yemail,

                        yclientToken = yregister.yclientToken,
                        yaccessToken = yaccessToken,

                        ytime = getYTimeStamp().TotalMilliseconds
                    });
                    yregister.isYSuccess = true;
                    yregister.ymessage   = "注册成功";
                }
                else
                {
                    yregister.isYSuccess = false;
                    yregister.ymessage   = "验证码错误";
                    yregister.yuser      = new zyy_users();
                }
                this.SendAsync(JsonConvert.SerializeObject(new YingStruct()
                {
                    Ying  = "颖",
                    ytype = YingStruct.YingType.YRegister,
                    ydata = new YingStruct.YingData()
                    {
                        ycode    = 0,
                        ysender  = "Ying Server",
                        ymessage = JsonConvert.SerializeObject(yregister),
                        ydata    = null
                    }
                }), ycompleted);
                break;

            case YingStruct.YingType.YMessage:
                this.SendAsync(yevent.Data, ycompleted);
                break;

            case YingStruct.YingType.YMusic:
                this.SendAsync(yevent.Data, ycompleted);
                break;

            default:
                break;
            }
        }