private void ConvertCsObj(object csObj, ISFSObject sfsObj) { Type type = csObj.GetType(); string fullName = type.FullName; SerializableSFSType serializableSFSType = csObj as SerializableSFSType; if (serializableSFSType == null) { throw new SFSCodecError(string.Concat("Cannot serialize object: ", csObj, ", type: ", fullName, " -- It doesn't implement the SerializableSFSType interface")); } ISFSArray iSFSArray = SFSArray.NewInstance(); sfsObj.PutUtfString(CLASS_MARKER_KEY, fullName); sfsObj.PutSFSArray(CLASS_FIELDS_KEY, iSFSArray); FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { string name = fieldInfo.Name; object value = fieldInfo.GetValue(csObj); ISFSObject iSFSObject = SFSObject.NewInstance(); SFSDataWrapper sFSDataWrapper = WrapField(value); if (sFSDataWrapper != null) { iSFSObject.PutUtfString(FIELD_NAME_KEY, name); iSFSObject.Put(FIELD_VALUE_KEY, sFSDataWrapper); iSFSArray.AddSFSObject(iSFSObject); continue; } throw new SFSCodecError(string.Concat("Cannot serialize field of object: ", csObj, ", field: ", name, ", type: ", fieldInfo.GetType().Name, " -- unsupported type!")); } }
public void OnGameInfo(ISFSObject data) { if (data.ContainsKey("tptime")) { HupTime = data.GetInt("tptime"); } string hupInfo; if (data.ContainsKey("hup")) { hupInfo = data.GetUtfString("hup"); } else { return; } //接收重连解散信息 if (!string.IsNullOrEmpty(hupInfo)) { IsNotFirstTime = true; StartTime = data.ContainsKey("hupstart") ? data.GetLong("hupstart") : 0; string[] ids = hupInfo.Split(','); for (int i = 0; i < ids.Length; i++) { for (int j = 0, max = UserHupUp.Count; j < max; j++) { var id = int.Parse(ids[i]); if (id.Equals(int.Parse(UserHupUp[j].UserInfo.UserId))) { //2发起投票 3同意 -1拒绝 UserHupUp[j].Status = i == 0 ? HupType.Start : HupType.TongYi; if (id.Equals(int.Parse(SelfID))) { SelfChoose = true; } } } } ISFSObject sendObj = SFSObject.NewInstance(); ISFSArray arr = SFSArray.NewInstance(); foreach (HupUp hupUp in UserHupUp) { arr.AddSFSObject(hupUp.GetSfsObject()); } sendObj.PutSFSArray("Users", arr); sendObj.PutInt("HupTime", HupTime); sendObj.PutLong("StartTime", StartTime); sendObj.PutBool("SelfChoose", SelfChoose); //发送投票view EventObj.SendEvent("HupUpViewEvent", "HupUp", sendObj); } }
protected void OnHupUpResponse(object data) { ISFSObject obj = (ISFSObject)data; int id = obj.GetInt(RequestKey.KeyId); int starus = obj.GetInt(RequestKey.KeyType); if (starus == 2) { SelfChoose = false; foreach (HupUp hupUp in UserHupUp) { hupUp.Status = 0; } } foreach (HupUp hupUp in UserHupUp) { if (hupUp.UserInfo.UserId.Equals(id.ToString())) { hupUp.Status = (HupType)starus; } } if (id.Equals(int.Parse(SelfID))) { SelfChoose = true; } ISFSObject sendObj = SFSObject.NewInstance(); if (!IsNotFirstTime) { StartTime = JhFunc.GetTimeStamp(); IsNotFirstTime = true; sendObj.PutInt("HupTime", HupTime); sendObj.PutLong("StartTime", StartTime); } ISFSArray arr = SFSArray.NewInstance(); foreach (HupUp hupUp in UserHupUp) { arr.AddSFSObject(hupUp.GetSfsObject()); } sendObj.PutSFSArray("Users", arr); sendObj.PutBool("SelfChoose", SelfChoose); //发送投票view EventObj.SendEvent("HupUpViewEvent", "HupUp", sendObj); if (starus == -1) { CloseHup(); Reset(); } }
public void OnGuZhuYiZhi(ISFSObject response) { int gold = response.GetInt("goldinc"); bool isWin = response.GetBool("result"); JhUserInfo biUser = GetPlayerInfo <JhUserInfo>(CurrenPlayer, true); biUser.CoinA -= gold; TotalBet += gold; biUser.IsGzyz = false; List <int> lostList = new List <int>(); if (isWin) { foreach (var userInfo in UserInfoDict) { JhUserInfo jhUser = (JhUserInfo)userInfo.Value; if (jhUser != biUser) { jhUser.IsFail = true; lostList.Add(GetLocalSeat(jhUser.Seat)); } } } else { biUser.IsFail = true; lostList.Add(GetLocalSeat(CurrenPlayer)); } if (response.ContainsKey("fancha")) { ISFSArray arr = response.GetSFSArray("fancha"); for (int i = 0; i < arr.Count; i++) { ISFSObject obj = arr.GetSFSObject(i); int seat = obj.GetInt("seat"); int fancha = obj.GetInt("gold"); JhUserInfo fanUser = GetPlayerInfo <JhUserInfo>(seat, true); fanUser.CoinA += fancha; } } ISFSObject sendObj = SFSObject.NewInstance(); sendObj.PutInt("Chair", GetLocalSeat(CurrenPlayer)); sendObj.PutInt("Gold", gold); sendObj.PutBool("isWin", isWin); sendObj.PutUtfString("Name", biUser.Name); sendObj.PutIntArray("LostList", lostList.ToArray()); //如果存在 反差值的情况 刷新金币 if (response.ContainsKey("fancha")) { //刷新金币 ISFSArray arr = SFSArray.NewInstance(); foreach (var info in UserInfoDict) { JhUserInfo jhInfo = (JhUserInfo)info.Value; if (jhInfo.IsPlaying()) { ISFSObject obj = SFSObject.NewInstance(); obj.PutInt("Chair", GetLocalSeat(jhInfo.Seat)); obj.PutLong("Gold", jhInfo.CoinA); arr.AddSFSObject(obj); } } sendObj.PutSFSArray("FanCha", arr); } EventObj.SendEvent("PlayersViewEvent", "GZYZ", sendObj); EventObj.SendEvent("SoundEvent", "PlayerEffect", new JhSound.SoundData(JhSound.EnAudio.CompareAnimate)); EventObj.SendEvent("TableViewEvent", "Bet", TotalBet); }
protected void SendGameStatusToPlayerView() { ISFSObject sendObj = SFSObject.NewInstance(); ISFSArray sendArray = SFSArray.NewInstance(); foreach (var info in UserInfoDict) { JhUserInfo userInfo = (JhUserInfo)info.Value; if (userInfo != null) { ISFSObject obj = userInfo.GetSfsObject(RStatus); obj.PutInt("Chair", GetLocalSeat(userInfo.Seat)); sendArray.AddSFSObject(obj); } } sendObj.PutBool("isShowTimeTip", CoustemTime > 0); if (RStatus > RoomStatus.CanStart) { sendObj.PutInt("CurChair", GetLocalSeat(CurrenPlayer)); sendObj.PutDouble("CdTime", CdTime); sendObj.PutLong("LastTime", LastTime); if (CurrenPlayer == SelfSeat) { JhUserInfo curUser = GetPlayerInfo <JhUserInfo>(CurrenPlayer, true); if (!curUser.IsGzyz && IsAutoFollow) { sendObj.PutDouble("CdTime", 2.0f); } } JhUserInfo currP = GetPlayerInfo <JhUserInfo>(CurrenPlayer, true); SetCurrenPlayerBeatMinAndMax(currP, sendObj); sendObj.PutInt("Banker", GetLocalSeat(BankerSeat)); if (TotalBet != 0) { ISFSArray betArray = SFSArray.NewInstance(); int ttBet = TotalBet; for (int i = AnteRate.Count - 1; i >= 0; i--) { if (ttBet >= AnteRate[i]) { ISFSObject arrO = SFSObject.NewInstance(); arrO.PutInt("ChipValue", AnteRate[i]); arrO.PutInt("ChipIndex", i); arrO.PutInt("ChipCnt", ttBet / AnteRate[i]); betArray.AddSFSObject(arrO); ttBet = ttBet % AnteRate[i]; } } sendObj.PutSFSArray("ChipList", betArray); } } sendObj.PutSFSArray("Players", sendArray); sendObj.PutIntArray("Antes", AnteRate.ToArray()); sendObj.PutInt("SingleBet", SingleBet); sendObj.PutBool("IsPlaying", RStatus > RoomStatus.CanStart && RStatus != RoomStatus.Over); SetSfsUserContrl(sendObj); EventObj.SendEvent("PlayersViewEvent", "Status", sendObj); }
private void OnTtResult(object data) { ItemList.Clear(); JhGameTable GameData = App.GetGameData <JhGameTable>(); ISFSObject obj = (ISFSObject)data; ISFSArray usersArr = obj.GetSFSArray("users"); long time = obj.GetLong("svt"); for (int i = 0; i < usersArr.Count; i++) { ISFSObject objItem = usersArr.GetSFSObject(i); if (objItem.GetKeys().Length > 0) { var rItem = new TtResultItem { Name = objItem.GetUtfString("nick"), Avatar = objItem.GetUtfString("avatar"), Sex = objItem.GetShort("sex"), Gold = objItem.GetInt("gold"), WinCnt = objItem.GetInt("win"), LostCnt = objItem.GetInt("lose"), BipaiCnt = objItem.GetInt("abandon"), UId = objItem.GetInt("id") }; ItemList.Add(rItem); } } int bigWiner = 0; int cnt = 0; for (int i = 0; i < ItemList.Count; i++) { TtResultItem item = ItemList[i]; if (item.WinCnt > cnt) { bigWiner = i; cnt = item.WinCnt; } } ItemList[bigWiner].IsBigWinner = true; ISFSArray sendArr = SFSArray.NewInstance(); foreach (TtResultItem item in ItemList) { sendArr.AddSFSObject(item.GetSfsObj()); } ISFSObject sendObj = SFSObject.NewInstance(); sendObj.PutSFSArray("Users", sendArr); sendObj.PutUtfString("Time", DateTime.FromBinary(time).ToString()); sendObj.PutInt("MaxLun", GameData.maxRound); sendObj.PutInt("RoomID", GameData.CreateRoomInfo.RoomId); sendObj.PutInt("Ante", GameData.AnteRate[0]); sendObj.PutInt("Ju", GameData.CreateRoomInfo.CurRound); EventObj.SendEvent("TtResultViewEvent", "TtResultInfo", sendObj); }