Exemple #1
0
        protected override void OnMessage(MessageEventArgs e)
        {
            try
            {
                ServerLog.writeLog(string.Format("Player:{0}, Msg:", ID, e.Data));
                string data = e.Data;

                object jsonObject = new JavaScriptSerializer().DeserializeObject(data);
                IDictionary <string, object> payload = (IDictionary <string, object>)jsonObject;
                string pid = (string)payload["pid"];

                switch (pid)
                {
                case "LoginInfo":
                    LoginInfo loginInfo = new JavaScriptSerializer().ConvertToType <LoginInfo>(jsonObject);
                    ServerLog.writeLog(string.Format("Loginin GamePlayer:{0} DeviceId:{1}", ID, loginInfo.deviceId));
                    LoginInfoRes loginRes = new LoginInfoRes();
                    //Check LoginInfo
                    if (loginInfo.deviceId.Length > 10)
                    {
                        myDeviceID           = loginInfo.deviceId;
                        myNickName           = loginInfo.nickName;
                        loginRes.loginResult = 1;
                    }
                    sendData("LoginInfoRes", loginRes);
                    if (loginRes.loginResult > 0)
                    {
                        GameInfo gameinfo = new GameInfo();
                        sendData("GameInfo", gameinfo);
                    }
                    break;

                case "QuickSeatReq":
                    myGame = ServerApp.getGameTableActor().quickJoin(this);
                    break;

                case "MoveInfoReq":
                    MoveInfoReq moveInfo = new JavaScriptSerializer().ConvertToType <MoveInfoReq>(jsonObject);
                    myGame.moveInfoReq(moveInfo, isBlack);
                    break;

                case "GameResultInfo":
                    GameResultInfo gameResult = new JavaScriptSerializer().ConvertToType <GameResultInfo>(jsonObject);
                    if (gameResult.wiinnerIsme == true)
                    {
                        Task resultTask = new Task(() =>
                        {
                            Task.Delay(5000).Wait();
                            myGame.prePareGame();
                        });
                        resultTask.Start();
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                ServerLog.writeLog(ex.Message);
            }
        }
Exemple #2
0
 protected override void OnClose(CloseEventArgs e)
 {
     timer.Stop();
     if (myGame != null)
     {
         ServerApp.getGameTableActor().leaveGame(this);
         myGame = null;
     }
     ServerLog.writeLog(string.Format("OnClose GamePlayer:{0} , {1}", ID, e.Reason));
 }
Exemple #3
0
        protected override void OnError(ErrorEventArgs e)
        {
            timer.Stop();
            if (myGame != null)
            {
                ServerApp.getGameTableActor().leaveGame(this);
                myGame = null;
            }

            ServerLog.writeLog(string.Format("Onerror GamePlayer:{0} , {1}", ID, e.Message));
        }