protected void AddOtherPlayer(SFSObject data) { if (data.ContainsKey(Consts.X_ARRAY) && data.ContainsKey(Consts.Y_ARRAY) && data.ContainsKey(Consts.ID_ARRAY) && data.ContainsKey(Consts.R_ARRAY)) { double[] x = data.GetDoubleArray(Consts.X_ARRAY); double[] y = data.GetDoubleArray(Consts.X_ARRAY); double[] r = data.GetDoubleArray(Consts.X_ARRAY); double[] id = data.GetDoubleArray(Consts.X_ARRAY); if (!(x.Length == y.Length && y.Length == r.Length && r.Length == id.Length)) { return; } for (int i = 0; i < x.Length; i++) { if (!_tanks.ContainsKey((int)id[i])) { _tanks.Add((int)id[i], new Tank((int)id[i], (float)x[i], (float)y[i])); _tanks[_tanks.Count - 1].SetRotation((int)r[i]); } } } }
public static void HandleMessage(SFSObject msgObj) { if (msgObj.ContainsKey("js")) { int id = msgObj.GetInt("id"); for (int i = 0; i < screens.Count; ++i) { if (screens[i].bssId == id && !screens[i].bTex.isWebViewBusy()) { screens[i].ExecuteRemoteJavaScript(msgObj.GetUtfString("js")); return; } } Debug.LogError("Didn't find page: " + msgObj.GetInt("id") + " or webView was busy, did not execute js"); } if (msgObj.ContainsKey("pl")) { foreach (KeyValuePair <int, NewProductInvestmentsScreen> s in NewProductInvestmentsScreen.GetAll()) { s.Value.Refresh(); } ProductManagementScreen.HandleNewProductForAll(); } }
bool GetMouseMoved(MsgData msg) { if (msg.msgType != SFSEvent.OBJECT_MESSAGE) { return(false); } SFSObject dataObj = SFSObject.NewFromBinaryData(new ByteArray(msg.msg)); return(!dataObj.ContainsKey("type") && dataObj.ContainsKey("mpo")); }
public override void UpdateData(User user, SFSObject data) { if (data.ContainsKey(Consts.BHVR) && data.ContainsKey(Consts.GO_ID)) { int id = (int)data.GetDouble(Consts.GO_ID); string behavior = (string)data.GetUtfString(Consts.BHVR); if (_items != null && _items.ContainsKey(id)) { _items[id].Behavior(behavior); } } }
private void HandleOtherObjectMessages(int userID, SFSObject msgObj) { if (msgObj.ContainsKey("mp") || msgObj.ContainsKey("mpx") || msgObj.ContainsKey("me")) { RemoteMouseManager.Inst.OnObjectMessage(userID, msgObj); } if (GameManager.Inst.LevelLoaded == GameManager.Level.BIZSIM && BizSimManager.Inst.productMgr != null) { BizSimManager.Inst.productMgr.HandleMessageObject(msgObj); } if (msgObj.ContainsKey("url")) { Debug.LogError("url -- message no longer supported, use room variables to change shared web panels"); } if (msgObj.ContainsKey("js") || msgObj.ContainsKey("pl")) { BizSimScreen.HandleMessage(msgObj); } // Effects (confetti!) if (msgObj.ContainsKey("cnfon") || msgObj.ContainsKey("typn")) { PlayerManager.remoteEffectManager.OnObjectMessage(msgObj); } }
private void OnExtensionResponse(BaseEvent e) { print("OnLoginError"); string cmd = e.Params.GetValue<string>("cmd"); ISFSObject objIn = new SFSObject(); if (cmd == CMD_SIGNUP) { if (objIn.ContainsKey("errorMessage")) Debug.LogError("Signup error : " + objIn.GetUtfString("errorMessage")); else if(objIn.ContainsKey("success")) Debug.Log("Signup successful"); else Debug.LogError("Signup unknown error"); } }
public override void Add(User user, SFSObject data) { if (user != null) { if (data.ContainsKey(Consts.X) && data.ContainsKey(Consts.Y)) { if (!_tanks.ContainsKey(user.Id)) { _tanks.Add(user.Id, new Tank(user.Id, (float)data.GetDouble(Consts.X), (float)data.GetDouble(Consts.Y))); _tanks[user.Id].LoadContents(_contents); // AddOtherPlayer(data); } } } base.Add(user, data); }
public override void UpdateData(User user, SFSObject data) { int go_id = (data.ContainsKey(Consts.GO_ID)) ? (int)data.GetDouble(Consts.GO_ID) : -1; if (!(data.ContainsKey(Consts.X) && data.ContainsKey(Consts.Y))) { return; } if (go_id != -1) { if (_bullets.ContainsKey(go_id)) { _bullets[go_id].SetPosition(new Vector2((float)data.GetDouble(Consts.X), (float)data.GetDouble(Consts.Y))); } } base.UpdateData(user, data); }
public override void UpdateData(User user, SFSObject data) { User me = _network.GetInstance().MySelf; if (user != me && user != null) { if (_tanks.ContainsKey(user.Id)) { if (data.ContainsKey(Consts.X) && data.ContainsKey(Consts.Y) && data.ContainsKey(Consts.ROTATION)) { _tanks[user.Id].SetVariable((float)data.GetDouble(Consts.X), (float)data.GetDouble(Consts.Y), (int)data.GetDouble(Consts.ROTATION)); } } } base.UpdateData(user, data); }
public override void Add(Sfs2X.Entities.User user, SFSObject data) { if (_bullets != null) { if (data.ContainsKey(Consts.X) && (data.ContainsKey(Consts.Y) && data.ContainsKey(Consts.GO_ID))) { int objectId = (int)data.GetDouble(Consts.GO_ID); if (!_bullets.ContainsKey(objectId)) { _bullets.Add((int)data.GetDouble(Consts.GO_ID), new Bullet((float)data.GetDouble(Consts.X), (float)data.GetDouble(Consts.Y), (ulong)objectId)); _bullets[objectId].LoadContents(_contents); _s_fire.Play(); } } } base.Add(user, data); }
bool DidTalk(MsgData msg) { if (msg.msgType != SFSEvent.OBJECT_MESSAGE) { return(false); } SFSObject dataObj = SFSObject.NewFromBinaryData(new ByteArray(msg.msg)); return(dataObj.ContainsKey("type") && dataObj.GetUtfString("type") == "voice"); }
public override void Remove(User user, SFSObject data) { if (data.ContainsKey(Consts.GO_ID)) { int id = (int)data.GetDouble(Consts.GO_ID); if (_items.ContainsKey(id)) { _items.Remove(id); } } }
/// <summary> /// 初始化用户信息 /// </summary> /// <param name="data"></param> public void Init(SFSObject data) { if (data == null) { return; } if (data.ContainsKey("User")) { User = data.GetUtfString("User"); } if (data.ContainsKey("Id")) { Id = data.GetInt("Id"); } if (data.ContainsKey("isMe")) { IsMe = data.GetBool("isMe"); } }
public override void Add(User user, SFSObject data) { if (_items != null) { if (!(data.ContainsKey(Consts.X) && data.ContainsKey(Consts.Y) && data.ContainsKey(Consts.GO_ID) && data.ContainsKey(Consts.TYPE_KIND_OF_ITEM))) { return; } float x = (float)data.GetDouble(Consts.X); float y = (float)data.GetDouble(Consts.Y); int id = (int)data.GetDouble(Consts.GO_ID); int itemKind = (int)data.GetDouble(Consts.TYPE_KIND_OF_ITEM); if (_items.ContainsKey(id)) { return; } #region add item switch (itemKind) { case 0: { _items.Add(id, new Item(x, y, Consts.ES_ITEM_HP)); break; } case 1: { _items.Add(id, new Item(x, y, Consts.ES_ITEM_POWER_UP)); break; } } #endregion _items[id].LoadContents(_contents); } }
private void OnExtensionResponse(BaseEvent e) { print("OnLoginError"); string cmd = e.Params.GetValue <string>("cmd"); ISFSObject objIn = new SFSObject(); if (cmd == CMD_SIGNUP) { if (objIn.ContainsKey("errorMessage")) { Debug.LogError("Signup error : " + objIn.GetUtfString("errorMessage")); } else if (objIn.ContainsKey("success")) { Debug.Log("Signup successful"); } else { Debug.LogError("Signup unknown error"); } } }
public override void Remove(User user, SFSObject data) { if (!data.ContainsKey(Consts.GO_ID)) { return; } else { int objectId = (int)data.GetDouble(Consts.GO_ID); if (_bullets.ContainsKey(objectId)) { _bullets.Remove(objectId); } } base.Remove(user, data); }
private int FindNextVoiceMsg(List <MsgData> msgData, int startOffset) { for (int i = startOffset; i < msgData.Count; ++i) { MsgData msg = msgData[i]; if (msg.msgType == SFSEvent.OBJECT_MESSAGE && msg.msg != null) { SFSObject dataObj = SFSObject.NewFromBinaryData(new ByteArray(msg.msg)); if (dataObj.ContainsKey("type") && dataObj.GetUtfString("type") == "voice") { return(i); } } } return(msgData.Count - 1); }
private void OnExtensionResponse(BaseEvent e) { string cmd = (string)e.Params["cmd"]; SFSObject data = (SFSObject)e.Params["params"]; if (cmd == "gameisplaying") { if (data.ContainsKey("value")) { _sfs.Send(new LeaveRoomRequest(_sfs.LastJoinedRoom)); _gameIsPlaying = (bool)data.GetBool("value"); _okButton.CMD(Consts.UI_CMD_ENABLE); Tank myseft = (Tank)_network.GetMainTank(); if (!myseft.IsAlive()) { myseft.ReGeneration(); } } } }
public void HandleObjectMessage(int userID, SFSObject dataObj) { //we are ignoring all msgs that doesnt have a "type" defined if (!dataObj.ContainsKey("type")) { HandleOtherObjectMessages(userID, dataObj); // support messages that don't conform to the "type" system for now. return; } switch (dataObj.GetUtfString("type")) { case "anim": { Player player = GameManager.Inst.playerManager.GetPlayer(userID); if (player != null) { string animName = dataObj.GetUtfString("anim"); player.gameObject.GetComponent <AnimatorHelper>().StartAnim(animName, false); } } break; case "panim": { Player player = GameManager.Inst.playerManager.GetPlayer(userID); if (player != null) { string animName = dataObj.GetUtfString("anim"); player.gameObject.GetComponent <AnimatorHelper>().StopAnim(animName, false); } } break; case "cmd": switch (dataObj.GetUtfString("cmd")) { case "rm": GameGUI.Inst.WriteToConsoleLog("Removing player unit from " + userID); // GameManager.Inst.playerManager.RemoveRemotePlayer(sender); break; case "whisper": GameGUI.Inst.WriteToConsoleLog("whispering pm from " + userID); break; } break; case "voice": VoiceManager.Inst.HandleMessage(dataObj); break; case "screen": Debug.LogError("Got Screen message, contains rs?: " + (dataObj.ContainsKey("type") ? "yes" : "no")); int stageItemID = dataObj.GetInt("rs"); BizSimScreen.RefreshScreen(stageItemID); break; case "ss": if (StrategyScreen.Inst != null) { StrategyScreen.Inst.HandleMessage(dataObj); } break; } }
public void onHorseVariablesChanged(SFSObject aObject) { if (aObject.ContainsKey ("h" + this.horseIndex)) { SFSObject thisHorseObject = (SFSObject) aObject.GetSFSObject ("h" + this.horseIndex); dataFromServer (thisHorseObject.GetInt ("u"), thisHorseObject.GetUtfString ("c")); } else { ownerID = 0; } }
private void OnExtensionResponse(BaseEvent e) { string cmd = (string)e.Params["cmd"]; SFSObject data = (SFSObject)e.Params["params"]; User user = (User)e.Params["user"]; try { if (cmd == Consts.CMD_IS_PRIMARY) { _network.SetPrimary((int)data.GetShort(Consts.ROOM_ONWER)); _isEnablePlayButton = (_network.IsPrimary() == _sfs.MySelf.Id) ? true : false; if (!_isEnablePlayButton) { _playButton.CMD(Consts.UI_CMD_DISABLE); } else { _readyButton.CMD(Consts.UI_CMD_DISABLE); return; } //////////////// dis play ready state //////////////// if (data.ContainsKey(Consts.READY_ARRAY) && data.ContainsKey(Consts.ID_ARRAY)) { short[] id = data.GetShortArray(Consts.ID_ARRAY); bool[] ready = data.GetBoolArray(Consts.READY_ARRAY); for (int i = 0; i < id.Length; i++) { User userReady = _network.GetCurretRoom().GetUserById((int)id[i]); if (userReady != null) { bool isOwner = (_network.IsPrimary() == userReady.Id) ? true : false; _namePlates.Add(userReady, isOwner); _namePlates.SetReady((int)id[i], ready[i]); } } } Debug.WriteLine("Is primary :" + _isEnablePlayButton); return; } if (cmd == Consts.CMD_USER_READY) { if (data.ContainsKey(Consts.CAN_PLAY)) { if (_network.IsPrimary() == _sfs.MySelf.Id) { if (data.ContainsKey(Consts.MESSAGE)) { Debug.WriteLine(data.GetUtfString(Consts.MESSAGE)); } } bool canPlay = data.GetBool(Consts.CAN_PLAY); if (canPlay) { Game1.sceneManager.GotoScene(Consts.SCENE_PLAY); } return; } if (data.ContainsKey(Consts.ID_ARRAY) && data.ContainsKey(Consts.READY_ARRAY)) { short[] id = data.GetShortArray(Consts.ID_ARRAY); bool[] isReady = data.GetBoolArray(Consts.READY_ARRAY); for (int i = 0; i < id.Length; i++) { _namePlates.SetReady((int)id[i], isReady[i]); } } return; } }catch (Exception exp) { Debug.WriteLine(exp.ToString()); } }
public void handleRacePositionsBroadcast(SFSObject aObject) { if(aObject.ContainsKey("a")) { SFSArray a = (SFSArray) aObject.GetSFSArray("a"); int f = aObject.GetInt("f"); for(int i = 0;i<a.Size();i++) { initPacketFromHost((SFSObject) a.GetSFSObject(i)); } //Time.timeScale = 0.01f; for(int i = f;i<framesPassed;i++) { for(int j = 0;j<this.sortedHorses.Count;j++) { sortedHorses[j].FixedUpdate(); } } for(int i = 0;i<sortedHorses.Count;i++) { Vector3 posDiff = sortedHorses[i].transform.position-sortedHorses[i].originalPosition; // Debug.Log ("Position was wrong by: "+posDiff+" last applied speed was: "+sortedHorses[i].lastAppliedSpeed); } } }