protected void RecieveAdventureSceneData(TCPMessageType tcpMessageType, object messageObj) { if (this.isDisconnected) { global::Debug.Log("AdventureSceneData: 切断中"); return; } global::Debug.Log("AdventureSceneData: 受信"); AdventureSceneData data = TCPData <AdventureSceneData> .Convert(messageObj); if (this.CheckHash(data.hashValue)) { return; } this.lastAction[tcpMessageType] = delegate() { this.isAdventureSceneAllEnd = (data.isEnd == 1); if (this.isAdventureSceneAllEnd) { this.adventureSceneEndList.Clear(); } this.recieveChecks[tcpMessageType] = true; }; int num = (!base.stateManager.battleAdventureSceneManager.isUpdate) ? 1 : 0; this.SendConfirmation(tcpMessageType, data.playerUserId, num.ToString()); }
private IEnumerator SendConfirm <T>(TCPMessageType tcpMessageType, TCPData <T> message, string targetId, bool enableDisconnected = true) where T : class { global::Debug.LogFormat("Send tcpMessageType:{0}", new object[] { tcpMessageType }); float sendWaitTime = 2f; for (;;) { if (sendWaitTime >= 2f) { sendWaitTime = 0f; this.SendMessageForTarget(tcpMessageType, message, new string[] { targetId }, enableDisconnected); } sendWaitTime += Time.unscaledDeltaTime; if (this.otherUserCount == 0 || this.confirmationChecks[tcpMessageType].Where((string item) => item == targetId).Any <string>()) { break; } yield return(null); } this.confirmationChecks[tcpMessageType].Clear(); yield break; yield break; }
public void Initialize() { this.CurrentEnemyMyIndex = -1; this.recieveChecks = new Dictionary <TCPMessageType, bool>(); this.confirmationChecks = new Dictionary <TCPMessageType, List <string> >(); IEnumerator enumerator = Enum.GetValues(typeof(TCPMessageType)).GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; TCPMessageType key = (TCPMessageType)obj; this.recieveChecks[key] = false; this.confirmationChecks[key] = new List <string>(); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } this.multiUsers = ClassSingleton <MultiBattleData> .Instance.PvPUserDatas; this.IsOwner = this.multiUsers.Any((MultiBattleData.PvPUserData item) => item.userStatus.userId == ClassSingleton <MultiBattleData> .Instance.MyPlayerUserId && item.isOwner); base.stateManager.onApplicationPause.Add(new Action <bool>(this.OnApplicationPause)); }
private void SendMessageForTarget(TCPMessageType tcpMessageType, object message, string[] targetIds, bool enableDisconnected = true) { if (enableDisconnected && this.isDisconnected) { return; } Dictionary <string, object> dictionary = ClassSingleton <TCPMessageFactory> .Instance.CreateMessage(tcpMessageType, message); if (this.multiUsers == null || this.multiUsers.Length == 0) { return; } global::Debug.Log("targetIds: " + targetIds); if (Singleton <TCPUtil> .Instance == null) { global::Debug.LogWarning("this.myTCPUtil is null"); } else { TCPUtil instance = Singleton <TCPUtil> .Instance; Dictionary <string, object> data = dictionary; if (BattleMultiBasicFunction.< > f__mg$cache0 == null) { BattleMultiBasicFunction.< > f__mg$cache0 = new Func <string, int>(Util.ToInt32); } instance.SendTCPRequest(data, targetIds.Select(BattleMultiBasicFunction.< > f__mg$cache0).ToList <int>(), this.myTCPKey); global::Debug.LogFormat("[TCPMessage]{0}を送信しました.", new object[] { tcpMessageType }); } }
protected virtual void RecieveRandomSeedSync(TCPMessageType tcpMessageType, object messageObj) { if (this.isDisconnected) { global::Debug.Log("RandomSeedSync: 切断中"); return; } global::Debug.Log("RandomSeedSync: 受信"); if (base.stateManager.rootState.currentState.GetType() != typeof(SubStateWaitRandomSeedSync)) { return; } RandomSeedSyncData randomSeedSyncData = TCPData <RandomSeedSyncData> .Convert(messageObj); if (this.CheckRecieveData(randomSeedSyncData.playerUserId, randomSeedSyncData.hashValue)) { return; } this.lastAction[TCPMessageType.RandomSeedSync] = delegate() { global::Debug.LogFormat("randomSeed:{0}", new object[] { randomSeedSyncData.randomSeed }); UnityEngine.Random.InitState(randomSeedSyncData.randomSeed); this.recieveChecks[TCPMessageType.RandomSeedSync] = true; }; this.SendConfirmation(tcpMessageType, randomSeedSyncData.playerUserId, string.Empty); }
public Dictionary <string, object> CreateMessage(TCPMessageType type, object tcpMessage) { return(new Dictionary <string, object> { { type.ToString(), tcpMessage } }); }
private void RecieveEmotion(TCPMessageType tcpMessageType, object messageObj) { global::Debug.Log("Emotion: 受信"); EmotionData emotionData = TCPData <EmotionData> .Convert(messageObj); string spriteName = emotionData.spriteName; int iconSpritesIndex = emotionData.iconSpritesIndex; bool isOther = true; base.stateManager.uiControlPvP.ShowEmotion(iconSpritesIndex, spriteName, isOther); }
public string CreateHash(TCPMessageType tcpMessageType, string userId, TCPMessageType tcpMessageTypeForLastConfirmation = TCPMessageType.None) { string inputString = string.Format("{0}_{1}_{2}_{3}", new object[] { userId, tcpMessageType, tcpMessageTypeForLastConfirmation, DateTime.Now.ToString("yyyyMMddhhmmssffff") }); return(Util.GetHashString(inputString)); }
protected virtual void RecieveAttack(TCPMessageType tcpMessageType, object messageObj) { if (this.isDisconnected) { global::Debug.Log("Attack: 切断中"); return; } global::Debug.Log("Attack: 受信"); if (base.stateManager.rootState.currentState.GetType() != typeof(SubStateMultiWaitEnemySkillSelect) && base.stateManager.rootState.currentState.GetType() != typeof(SubStateWaitEnemySkillSelect)) { global::Debug.LogWarning("まだ準備していない"); return; } AttackData attackData = TCPData <AttackData> .Convert(messageObj); if (this.CheckRecieveData(attackData.playerUserId, attackData.hashValue)) { return; } this.lastAction[TCPMessageType.Attack] = delegate() { CharacterStateControl currentSelectCharacterState = this.battleStateData.currentSelectCharacterState; int targetIdx = attackData.targetIdx; int selectSkillIdx = attackData.selectSkillIdx; if (this.battleStateData.currentSelectCharacterState.isEnemy) { if (attackData.isTargetCharacterEnemy) { currentSelectCharacterState.targetCharacter = this.battleStateData.playerCharacters[targetIdx]; } else { currentSelectCharacterState.targetCharacter = this.battleStateData.enemies[targetIdx]; } } else if (attackData.isTargetCharacterEnemy) { currentSelectCharacterState.targetCharacter = this.battleStateData.enemies[targetIdx]; } else { currentSelectCharacterState.targetCharacter = this.battleStateData.playerCharacters[targetIdx]; } currentSelectCharacterState.targetCharacter.myIndex = targetIdx; currentSelectCharacterState.isSelectSkill = selectSkillIdx; this.battleStateData.onSkillTrigger = true; this.recieveChecks[TCPMessageType.Attack] = true; }; this.SendConfirmation(tcpMessageType, attackData.playerUserId, string.Empty); }
protected void RunLastAction(TCPMessageType tcpMessageType) { if (this.lastAction.ContainsKey(tcpMessageType)) { this.lastAction[tcpMessageType](); } else { global::Debug.LogWarningFormat("{0}はthis.lastAction内にない", new object[] { tcpMessageType }); } }
public IEnumerator SendMessageInsistently <T>(TCPMessageType tcpMessageType, TCPData <T> message, List <int> TCPSendUserIdList, string TCPKey = "activityList", Action <List <int> > SendFaildAction = null) where T : class { TCPUtil.isTCPSending = true; int waitingCount = 0; List <int> InsistentlySendUserIdList = new List <int>(); foreach (int item in TCPSendUserIdList) { InsistentlySendUserIdList.Add(item); } for (;;) { global::Debug.LogFormat("[SendMessage] tcpMessageType:{0}, MyPlayerUserId:{1} , waitingCount:{2}", new object[] { tcpMessageType, this.myUserId, waitingCount }); for (int i = 0; i < this.confirmationChecks[tcpMessageType].Count; i++) { InsistentlySendUserIdList.Remove(int.Parse(this.confirmationChecks[tcpMessageType][i])); } bool sendResult = this.SendMessageForTarget(tcpMessageType, message, InsistentlySendUserIdList, TCPKey); yield return(AppCoroutine.Start(Util.WaitForRealTime(1f), false)); waitingCount++; bool finishForcely = false; if ((float)waitingCount >= 10f || !sendResult) { finishForcely = true; if ((float)waitingCount >= 10f && SendFaildAction != null) { SendFaildAction(InsistentlySendUserIdList); } } if (this.confirmationChecks[tcpMessageType].Count == TCPSendUserIdList.Count || finishForcely) { break; } yield return(null); } this.confirmationChecks[tcpMessageType].Clear(); TCPUtil.isTCPSending = false; global::Debug.LogFormat("[PacketEnd] tcpMessageType:{0}", new object[] { tcpMessageType }); yield break; yield break; }
protected override void RunRecieverPlayerActions(TCPMessageType tcpMessageType, object messageObj) { switch (tcpMessageType) { case TCPMessageType.None: return; case TCPMessageType.EnemyTurnSync: this.RecieveEnemyTurnSync(tcpMessageType, messageObj); break; case TCPMessageType.RandomSeedSync: this.RecieveRandomSeedSync(tcpMessageType, messageObj); break; case TCPMessageType.Emotion: this.RecieveEmotion(tcpMessageType, messageObj); break; default: if (tcpMessageType != TCPMessageType.LeaderChange) { if (tcpMessageType == TCPMessageType.AdventureScene) { base.RecieveAdventureSceneData(tcpMessageType, messageObj); } } else { base.RecieveLeaderChange(tcpMessageType, messageObj); } break; case TCPMessageType.Attack: this.RecieveAttack(tcpMessageType, messageObj); break; case TCPMessageType.Retire: this.RecieveRetire(tcpMessageType, messageObj); break; case TCPMessageType.Confirmation: base.RecieveConfirmation(tcpMessageType, messageObj); break; case TCPMessageType.LastConfirmation: base.RecieveLastConfirmation(tcpMessageType, messageObj); break; } }
public override IEnumerator SendMessageInsistently <T>(TCPMessageType tcpMessageType, TCPData <T> message, float waitingTerm = 2f) { global::Debug.LogFormat("Send tcpMessageType:{0}", new object[] { tcpMessageType }); float sendWaitTime = waitingTerm; float sendTotalWaitTime = 0f; for (;;) { while (this.isSendEvent || this.isDisconnected || this.isEnemyFailedAction) { yield return(null); } if (sendWaitTime >= waitingTerm) { sendWaitTime = 0f; base.SendMessageForSync(tcpMessageType, message); } if (sendTotalWaitTime >= 45f) { sendTotalWaitTime = 0f; IEnumerator enemyFailedAction = this.EnemyFailedAction(); while (enemyFailedAction.MoveNext()) { yield return(null); } } if (this.confirmationChecks[tcpMessageType].Count == base.otherUserCount) { break; } sendWaitTime += Time.unscaledDeltaTime; sendTotalWaitTime += Time.unscaledDeltaTime; yield return(null); } LastConfirmationData message2 = new LastConfirmationData { playerUserId = ClassSingleton <MultiBattleData> .Instance.MyPlayerUserId, hashValue = Singleton <TCPUtil> .Instance.CreateHash(TCPMessageType.LastConfirmation, ClassSingleton <MultiBattleData> .Instance.MyPlayerUserId, tcpMessageType), tcpMessageType = tcpMessageType.ToInteger() }; base.SendMessageForSync(TCPMessageType.LastConfirmation, message2); this.confirmationChecks[tcpMessageType].Clear(); yield break; yield break; }
private void SendMessageForSync(TCPMessageType tcpMessageType, object message, bool enableDisconnected) { List <string> list = this.GetOtherUsersId().ToList <string>(); if (list.Count <= 0) { global::Debug.LogFormat("{0} 今は自分だけ", new object[] { tcpMessageType }); this.confirmationChecks[tcpMessageType].Clear(); return; } this.SendMessageForTarget(tcpMessageType, message, list.ToArray(), enableDisconnected); }
private void RecieveEnemyTurnSync(TCPMessageType tcpMessageType, object messageObj) { global::Debug.Log("EnemyTurnSync: 受信"); EnemyTurnSyncData enemyTurnSyncData = TCPData <EnemyTurnSyncData> .Convert(messageObj); if (base.CheckRecieveData(enemyTurnSyncData.playerUserId, enemyTurnSyncData.hashValue)) { return; } this.lastAction[TCPMessageType.EnemyTurnSync] = delegate() { this.recieveChecks[TCPMessageType.EnemyTurnSync] = true; }; base.SendConfirmationDisconnected(tcpMessageType, enemyTurnSyncData.playerUserId, string.Empty); }
protected void RecieveLastConfirmation(TCPMessageType tcpMessageType, object messageObj) { global::Debug.Log("LastConfirmation: 受信"); LastConfirmationData lastConfirmationData = TCPData <LastConfirmationData> .Convert(messageObj); if (this.CheckRecieveData(lastConfirmationData.playerUserId, lastConfirmationData.hashValue)) { return; } this.confirmationChecks[TCPMessageType.Confirmation].Add(lastConfirmationData.playerUserId); this.RunLastAction((TCPMessageType)lastConfirmationData.tcpMessageType); global::Debug.LogFormat("tcpMessageType:{0}", new object[] { (TCPMessageType)lastConfirmationData.tcpMessageType }); }
public bool SendMessageForTarget(TCPMessageType tcpMessageType, object message, List <int> TCPSendUserIdList, string TCPKey = "activityList") { Dictionary <string, object> data = ClassSingleton <TCPMessageFactory> .Instance.CreateMessage(tcpMessageType, message); if (TCPSendUserIdList == null || TCPSendUserIdList.Count == 0) { return(false); } if (this.CheckTCPConnection()) { this.SendTCPRequest(data, TCPSendUserIdList, TCPKey); return(true); } global::Debug.LogError("TCP not connect"); return(false); }
protected virtual void TCPCallbackMethod(Dictionary <string, object> arg) { if (!arg.ContainsKey(this.myTCPKey)) { global::Debug.LogWarningFormat("{0} is not valid key.", new object[] { arg.Keys.First <string>() }); return; } Dictionary <object, object> dictionary = arg[this.myTCPKey] as Dictionary <object, object>; string text = dictionary.Keys.First <object>().ToString(); TCPMessageType tcpMessageType = MultiTools.StringToEnum <TCPMessageType>(text); object messageObj = dictionary[text]; this.RunRecieverPlayerActions(tcpMessageType, messageObj); }
private void RecieveRetire(TCPMessageType tcpMessageType, object messageObj) { global::Debug.Log("Retire: リタイア"); RetireData retierData = TCPData <RetireData> .Convert(messageObj); if (base.CheckRecieveData(retierData.playerUserId, retierData.hashValue)) { return; } this.lastAction[TCPMessageType.Retire] = delegate() { if (retierData.retiredPlayerId != ClassSingleton <MultiBattleData> .Instance.MyPlayerUserId) { this.ShowWinDialog(); } }; base.SendConfirmation(tcpMessageType, retierData.playerUserId, string.Empty); }
private void SendConfirmation(TCPMessageType tcpMessageType, string targetId, string value1, bool enableDisconnected) { global::Debug.LogFormat("[SendConfirmation] tcpMessageType:{0}, MyPlayerUserId:{1}, targetId:{2}", new object[] { tcpMessageType, ClassSingleton <MultiBattleData> .Instance.MyPlayerUserId, targetId }); ConfirmationData message = new ConfirmationData { playerUserId = ClassSingleton <MultiBattleData> .Instance.MyPlayerUserId, hashValue = Singleton <TCPUtil> .Instance.CreateHash(TCPMessageType.Confirmation, ClassSingleton <MultiBattleData> .Instance.MyPlayerUserId, TCPMessageType.None), tcpMessageType = tcpMessageType.ToInteger(), value1 = value1 }; AppCoroutine.Start(this.SendConfirm <ConfirmationData>(TCPMessageType.Confirmation, message, targetId, enableDisconnected), false); }
public void SendConfirmation(TCPMessageType tcpMessageType, string targetId, string myUserId, string tcpKey) { global::Debug.LogFormat("[SendConfirmation] tcpMessageType:{0}, MyPlayerUserId:{1}, targetId:{2}", new object[] { tcpMessageType, myUserId, targetId }); ConfirmationData message = new ConfirmationData { playerUserId = myUserId, hashValue = this.CreateHash(TCPMessageType.Confirmation, myUserId, TCPMessageType.None), tcpMessageType = tcpMessageType.ToInteger() }; this.SendMessageForTarget(TCPMessageType.Confirmation, message, new List <int> { targetId.ToInt32() }, tcpKey); }
protected void RecieveLeaderChange(TCPMessageType tcpMessageType, object messageObj) { if (this.isDisconnected) { global::Debug.Log("LeaderChange: 切断中"); return; } global::Debug.Log("LeaderChange: 受信"); LeaderChangeData data = TCPData <LeaderChangeData> .Convert(messageObj); if (this.CheckHash(data.hashValue)) { return; } this.lastAction[tcpMessageType] = delegate() { this.battleStateData.ChangePlayerLeader(data.leaderIndex); this.battleStateData.ChangeEnemyLeader(data.leaderIndex); this.recieveChecks[tcpMessageType] = true; }; this.SendConfirmation(tcpMessageType, data.playerUserId, string.Empty); }
public override IEnumerator WaitAllPlayers(TCPMessageType tcpMessageType) { global::Debug.LogFormat("Wait tcpMessageType:{0}", new object[] { tcpMessageType }); float waitingCount = 0f; for (;;) { while (this.isSendEvent || this.isDisconnected) { yield return(null); } if (waitingCount >= 45f) { waitingCount = 0f; IEnumerator enemyFailedAction = this.EnemyFailedAction(); while (enemyFailedAction.MoveNext()) { yield return(null); } } if (this.recieveChecks[tcpMessageType]) { break; } waitingCount += Time.unscaledDeltaTime; yield return(null); } global::Debug.LogFormat("Finish waiting [{0}].", new object[] { tcpMessageType }); this.recieveChecks[tcpMessageType] = false; yield break; yield break; }
protected void RecieveConfirmation(TCPMessageType tcpMessageType, object messageObj) { global::Debug.Log("Confirmation: 受信"); ConfirmationData confirmationData = TCPData <ConfirmationData> .Convert(messageObj); if (this.CheckRecieveData(confirmationData.playerUserId, confirmationData.hashValue)) { return; } TCPMessageType tcpMessageType2 = (TCPMessageType)confirmationData.tcpMessageType; this.confirmationChecks[tcpMessageType2].Add(confirmationData.playerUserId); global::Debug.LogFormat("confirmationChecks : {0}から確認用{1}を受信しました. Count:{2}", new object[] { confirmationData.playerUserId, tcpMessageType2, this.confirmationChecks[tcpMessageType2].Count }); if (tcpMessageType2 == TCPMessageType.AdventureScene && confirmationData.value1 == "1" && !this.adventureSceneEndList.Contains(confirmationData.playerUserId)) { this.adventureSceneEndList.Add(confirmationData.playerUserId); } }
public void InitConfirmationChecks() { TCPUtil.isTCPSending = false; this.confirmationChecks = new Dictionary <TCPMessageType, List <string> >(); IEnumerator enumerator = Enum.GetValues(typeof(TCPMessageType)).GetEnumerator(); try { while (enumerator.MoveNext()) { object obj = enumerator.Current; TCPMessageType key = (TCPMessageType)obj; this.confirmationChecks[key] = new List <string>(); } } finally { IDisposable disposable; if ((disposable = (enumerator as IDisposable)) != null) { disposable.Dispose(); } } }
public abstract IEnumerator WaitAllPlayers(TCPMessageType tcpMessageType);
public abstract IEnumerator SendMessageInsistently <T>(TCPMessageType tcpMessageType, TCPData <T> message, float waitingTerm = 2f) where T : class;
protected void SendMessageForSyncDisconnected(TCPMessageType tcpMessageType, object message) { this.SendMessageForSync(tcpMessageType, message, false); }
protected void SendMessageForSync(TCPMessageType tcpMessageType, object message) { this.SendMessageForSync(tcpMessageType, message, true); }
protected void SendConfirmationDisconnected(TCPMessageType tcpMessageType, string targetId, string value1 = "") { this.SendConfirmation(tcpMessageType, targetId, value1, false); }