Ejemplo n.º 1
0
        private ISFSArray UnrollArray(ArrayList arr)
        {
            ISFSArray   iSFSArray  = SFSArray.NewInstance();
            IEnumerator enumerator = arr.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object         current        = enumerator.Current;
                    SFSDataWrapper sFSDataWrapper = WrapField(current);
                    if (sFSDataWrapper == null)
                    {
                        throw new SFSCodecError(string.Concat("Cannot serialize field of array: ", current, " -- unsupported type!"));
                    }
                    iSFSArray.Add(sFSDataWrapper);
                }
                return(iSFSArray);
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = enumerator as IDisposable) != null)
                {
                    disposable.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        private ISFSArray DecodeSFSArray(ByteArray buffer)
        {
            //Discarded unreachable code: IL_00c1
            ISFSArray   iSFSArray   = SFSArray.NewInstance();
            SFSDataType sFSDataType = (SFSDataType)Convert.ToInt32(buffer.ReadByte());

            if (sFSDataType != SFSDataType.SFS_ARRAY)
            {
                throw new SFSCodecError(string.Concat("Invalid SFSDataType. Expected: ", SFSDataType.SFS_ARRAY, ", found: ", sFSDataType));
            }
            int num = buffer.ReadShort();

            if (num < 0)
            {
                throw new SFSCodecError("Can't decode SFSArray. Size is negative: " + num);
            }
            try
            {
                for (int i = 0; i < num; i++)
                {
                    SFSDataWrapper sFSDataWrapper = DecodeObject(buffer);
                    if (sFSDataWrapper != null)
                    {
                        iSFSArray.Add(sFSDataWrapper);
                        continue;
                    }
                    throw new SFSCodecError("Could not decode SFSArray item at index: " + i);
                }
                return(iSFSArray);
            }
            catch (SFSCodecError sFSCodecError)
            {
                throw sFSCodecError;
            }
        }
Ejemplo n.º 3
0
        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!"));
            }
        }
Ejemplo n.º 4
0
        public void OnResult(ISFSObject response)
        {
            RStatus = RoomStatus.Over;
            int[]      cards = response.GetIntArray("cards");
            JhUserInfo self  = GetPlayerInfo <JhUserInfo>();

            self.Cards = cards;
            ISFSArray users = response.GetSFSArray("users");

            for (int i = 0; i < users.Count; i++)
            {
                ISFSObject itemData = users.GetSFSObject(i);
                int        seat     = itemData.GetInt("seat");
                JhUserInfo user     = GetPlayerInfo <JhUserInfo>(seat, true);
                user.SetResult(itemData);
            }

            if (response.ContainsKey("compare"))
            {
                ISFSArray arr = response.GetSFSArray("compare");
                for (int i = 0; i < arr.Size(); i++)
                {
                    ISFSObject obj   = arr.GetSFSObject(i);
                    int        seat  = obj.GetInt("seat");
                    JhUserInfo uInfo = GetPlayerInfo <JhUserInfo>(seat, true);
                    uInfo.Cards = obj.GetIntArray("cards");
                    int[] cards1 = obj.GetIntArray("cards");
                    Debug.LogError(" result cards " + uInfo.NickM + "  " + cards1[0] + " " + cards1[1] + " " + cards1[2]);
                }
            }


            bool isWinner = false;

            ResultSfs = SFSArray.NewInstance();
            foreach (var useinfo in UserInfoDict)
            {
                if (useinfo.Value.IsPlayingGame)
                {
                    JhUserInfo jhUserInfo = ((JhUserInfo)useinfo.Value);
                    ISFSObject obj        = jhUserInfo.GetResultSfsObject();
                    obj.PutInt("Chair", useinfo.Key);

                    if (useinfo.Key == 0 && jhUserInfo.IsWinner)
                    {
                        isWinner = true;
                    }
                    obj.PutBool("IsWinner", isWinner);
                    ResultSfs.AddSFSObject(obj);
                }
            }

            EventObj.SendEvent("PlayersViewEvent", "Result", ResultSfs);

            ResultDelay = StartCoroutine(SendToResultView(ResultSfs));

            EventObj.SendEvent("SoundEvent", "PlayerEffect", new JhSound.SoundData(isWinner ? JhSound.EnAudio.Win : JhSound.EnAudio.Lost));
        }
Ejemplo n.º 5
0
        public virtual ISFSArray ToSFSArray()
        {
            ISFSArray iSFSArray = SFSArray.NewInstance();

            iSFSArray.AddUtfString(name);
            iSFSArray.AddByte((byte)type);
            PopulateArrayWithValue(iSFSArray);
            return(iSFSArray);
        }
Ejemplo n.º 6
0
        public override void Execute(SmartFox sfs)
        {
            ISFSArray iSFSArray = SFSArray.NewInstance();

            foreach (BuddyVariable buddyVariable in buddyVariables)
            {
                iSFSArray.AddSFSArray(buddyVariable.ToSFSArray());
            }
            sfso.PutSFSArray(KEY_BUDDY_VARS, iSFSArray);
        }
Ejemplo n.º 7
0
        public override void Execute(SmartFox sfs)
        {
            ISFSArray iSFSArray = SFSArray.NewInstance();

            foreach (UserVariable userVariable in userVariables)
            {
                iSFSArray.AddSFSArray(userVariable.ToSFSArray());
            }
            sfso.PutSFSArray(KEY_VAR_LIST, iSFSArray);
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        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 override void Execute(SmartFox sfs)
        {
            ISFSArray iSFSArray = SFSArray.NewInstance();

            foreach (RoomVariable roomVariable in roomVariables)
            {
                iSFSArray.AddSFSArray(roomVariable.ToSFSArray());
            }
            if (room == null)
            {
                room = sfs.LastJoinedRoom;
            }
            sfso.PutSFSArray(KEY_VAR_LIST, iSFSArray);
            sfso.PutInt(KEY_VAR_ROOM, room.Id);
        }
Ejemplo n.º 11
0
        public void Write(int chair)
        {
            SFSArray array = SFSArray.NewInstance();

            foreach (CpgSaveData saveData in _saveList[chair])
            {
                ISFSObject obj = new SFSObject();
                obj.PutInt(CpgType, (int)saveData.type);
                obj.PutIntArray(CpgValue, saveData.value);
                obj.PutInt(CpgIndex, saveData.index);

                array.AddSFSObject(obj);
            }
            string key = SaveDataKey + chair;

            PlayerPrefs.SetString(key, array.ToJson());
        }
Ejemplo n.º 12
0
        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);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
 public override void Execute(SmartFox sfs)
 {
     sfso.PutUtfString(KEY_NAME, settings.Name);
     sfso.PutUtfString(KEY_GROUP_ID, settings.GroupId);
     sfso.PutUtfString(KEY_PASSWORD, settings.Password);
     sfso.PutBool(KEY_ISGAME, settings.IsGame);
     sfso.PutShort(KEY_MAXUSERS, settings.MaxUsers);
     sfso.PutShort(KEY_MAXSPECTATORS, settings.MaxSpectators);
     sfso.PutShort(KEY_MAXVARS, settings.MaxVariables);
     sfso.PutBool(KEY_ALLOW_JOIN_INVITATION_BY_OWNER, settings.AllowOwnerOnlyInvitation);
     if (settings.Variables != null && settings.Variables.Count > 0)
     {
         ISFSArray iSFSArray = SFSArray.NewInstance();
         foreach (RoomVariable variable in settings.Variables)
         {
             if (variable is RoomVariable)
             {
                 RoomVariable roomVariable = variable as RoomVariable;
                 iSFSArray.AddSFSArray(roomVariable.ToSFSArray());
             }
         }
         sfso.PutSFSArray(KEY_ROOMVARS, iSFSArray);
     }
     if (settings.Permissions != null)
     {
         List <bool> list = new List <bool>();
         list.Add(settings.Permissions.AllowNameChange);
         list.Add(settings.Permissions.AllowPasswordStateChange);
         list.Add(settings.Permissions.AllowPublicMessages);
         list.Add(settings.Permissions.AllowResizing);
         sfso.PutBoolArray(KEY_PERMISSIONS, list.ToArray());
     }
     if (settings.Events != null)
     {
         List <bool> list2 = new List <bool>();
         list2.Add(settings.Events.AllowUserEnter);
         list2.Add(settings.Events.AllowUserExit);
         list2.Add(settings.Events.AllowUserCountChange);
         list2.Add(settings.Events.AllowUserVariablesUpdate);
         sfso.PutBoolArray(KEY_EVENTS, list2.ToArray());
     }
     if (settings.Extension != null)
     {
         sfso.PutUtfString(KEY_EXTID, settings.Extension.Id);
         sfso.PutUtfString(KEY_EXTCLASS, settings.Extension.ClassName);
         if (settings.Extension.PropertiesFile != null && settings.Extension.PropertiesFile.Length > 0)
         {
             sfso.PutUtfString(KEY_EXTPROP, settings.Extension.PropertiesFile);
         }
     }
     if (settings is MMORoomSettings)
     {
         MMORoomSettings mMORoomSettings = settings as MMORoomSettings;
         if (mMORoomSettings.DefaultAOI.IsFloat())
         {
             sfso.PutFloatArray(KEY_MMO_DEFAULT_AOI, mMORoomSettings.DefaultAOI.ToFloatArray());
             if (mMORoomSettings.MapLimits != null)
             {
                 sfso.PutFloatArray(KEY_MMO_MAP_LOW_LIMIT, mMORoomSettings.MapLimits.LowerLimit.ToFloatArray());
                 sfso.PutFloatArray(KEY_MMO_MAP_HIGH_LIMIT, mMORoomSettings.MapLimits.HigherLimit.ToFloatArray());
             }
         }
         else
         {
             sfso.PutIntArray(KEY_MMO_DEFAULT_AOI, mMORoomSettings.DefaultAOI.ToIntArray());
             if (mMORoomSettings.MapLimits != null)
             {
                 sfso.PutIntArray(KEY_MMO_MAP_LOW_LIMIT, mMORoomSettings.MapLimits.LowerLimit.ToIntArray());
                 sfso.PutIntArray(KEY_MMO_MAP_HIGH_LIMIT, mMORoomSettings.MapLimits.HigherLimit.ToIntArray());
             }
         }
         sfso.PutShort(KEY_MMO_USER_MAX_LIMBO_SECONDS, (short)mMORoomSettings.UserMaxLimboSeconds);
         sfso.PutShort(KEY_MMO_PROXIMITY_UPDATE_MILLIS, (short)mMORoomSettings.ProximityListUpdateMillis);
         sfso.PutBool(KEY_MMO_SEND_ENTRY_POINT, mMORoomSettings.SendAOIEntryPoint);
     }
     sfso.PutBool(KEY_AUTOJOIN, autoJoin);
     if (roomToLeave != null)
     {
         sfso.PutInt(KEY_ROOM_TO_LEAVE, roomToLeave.Id);
     }
 }
Ejemplo n.º 15
0
        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);
        }