public Operation1() { InitializeComponent(); mState = NetCode.Srvr1DatRetriving; mClnt = new Client2(ClntBufHndl, ClntBufPrep, true); mServer = new Server2(SrvrBufHndl); mServer.SrvrPort = 23821; mCbMsg = new UICbMsg(); bRunning = true; mBrd = new ExamBoard(); if (!System.IO.File.Exists("Room.txt") || !int.TryParse(System.IO.File.ReadAllText("Room.txt"), out uRId)) { uRId = 0; } vfbLock = new List <SortedList <int, bool> >(); System.Timers.Timer aTimer = new System.Timers.Timer(2000); // Hook up the Elapsed event for the timer. aTimer.Elapsed += UpdateSrvrMsg; aTimer.AutoReset = true; aTimer.Enabled = true; }
protected override void Initialize() { inv.Init(level, cmd); input.Init(level); chat.init(level, input, cmd); menu.init(input, cmd); cmd.init(this, level, chat, inv, menu, effectmanager, editor); level.init(input); editor.Init(level, input, GraphicsDevice.Viewport); sound.Init(level); hb.Init(level); foreach (var module in Global.mapModules) { module.Init(level); } NetCode.init(level, cmd); NetCode.Config = new NetPeerConfiguration("TestGame"); NetCode.Client = new NetClient(NetCode.Config); NetCode.Client.Start(); camera = new Camera(GraphicsDevice.Viewport); Global.Init(camera, time, sound, chat, cmd, new Random()); base.Initialize(); }
public NetMessage(byte[] data, ulong id) { this.code = (NetCode)data[0]; this.data = data; this.size = data.Length; this.id = id; }
// Use this for initialization async void Start() { Connect(); int port = await GetLobby(); client.Close(); NetCode.Connect(port); }
// Constructor public NetMessage(NetCode code, ulong id) { this.code = code; this.id = id; this.data = null; NetMessage.buffer[0] = (byte)code; this.size = 1; }
public void Initiate() { netCode = new NetCode(ipAddress, port); UInt16 packetType = PACKET_HI; netCode.SendMessage(packetType.ToString()); Debug.Log(PACKET_ACK + " " + PACKET_BYE + " " + PACKET_SNAP + " " + PACKET_HIT + " " + PACKET_HI + " " + PACKET_SPWN); isStarted = true; }
private void OnDestroy() { // Send to network if (NetCode.IsConnected) { var cmd = new Command(OpCode.Disconnect); NetCode.Send(cmd); } }
void Awake() { Instance = this; Debug.Log("Connecting"); PhotonNetwork.ConnectUsingSettings(); PhotonNetwork.GameVersion = GAME_VERSION; PhotonNetwork.NetworkingClient.EventReceived += OnEvent; }
// Update is called once per frame void Update() { if (elapsedTime >= period) { // Send a ping! NetCode.Send(cmd); elapsedTime = 0; } elapsedTime += Time.unscaledDeltaTime; }
public ExamineeA mNee;//reference to Auth.mNee public ExamPage() { InitializeComponent(); mState = NetCode.Dating; mClnt = new Client2(ClntBufHndl, ClntBufPrep, false); mCbMsg = new UICbMsg(); bRunning = true; mQSh = new QuestSheet(); }
public void Jump(float jumpMult = 1) { float velY = jumpHeight * jumpMult; pm.Jump(velY); // Send to network if (NetCode.IsConnected) { var cmd = new Command(OpCode.Jump, velY); NetCode.Send(cmd); } }
public void Move(float moveX) { float newX = Mathf.Max(-1, Mathf.Min(1, moveX)) * speed; if (newX != this.velX) { pm.MoveX(newX); if (NetCode.IsConnected) { var cmd = new Command(OpCode.Move, newX); NetCode.Send(cmd); } this.velX = newX; } }
public void Submit() { bBtnBusy = true;// spMain.Effect = null; WPopup.s.CbOK = null; bRunning = false; DisableAll(); mState = NetCode.Submiting; mNee.eStt = NeeStt.Submitting; mNee.ToLogFile(dtRemn.Minutes, dtRemn.Seconds); if (mClnt.ConnectWR(ref mCbMsg)) { bBtnBusy = false; } }
private void btnSubmit_Click(object sender, RoutedEventArgs e) { //todo: check th state to return mState = NetCode.SrvrSubmitting; Task.Run(() => { mClnt.ConnectWR(ref mCbMsg); }); }
public void Init(NetCode terminal) { mTerminal = terminal; }
public NetStateMsg Error(string msg) { code = NetCode.NetError; this.msg = msg; return(this); }
public NetStateMsg ConnectFail(string msg) { code = NetCode.ConnectFail; this.msg = msg; return(this); }
public override IEnumerator doReauest() { WWWForm wf = new WWWForm(); // wf.AddField("userid", Game.UserMgr.PlayerId); wf.AddField("identifier", GetRandomIdentifier()); wf.AddField("checksum", checkSum); wf.AddField("platform", GlobalConfig.GetPlatformId.ToString()); wf.AddField("version", GlobalConfig.GetVersion); if (null != args) { foreach (string key in args.Keys) { wf.AddField(key, args[key]); } } WWW sdw = new WWW(GlobalConfig.URL_ROOT + uri, wf); yield return(sdw); if (sdw.error != null) { Debug.LogWarning("uri:" + uri + "; msg:" + sdw.error); if (null != OnError) { OnError(NetCode.Unknown, sdw.error); } yield break; } if (sdw.error == null) { try { string result = sdw.text; Debug.Log("Return Json:" + result); Hashtable sdd = MiniJSON2.jsonDecode(result) as Hashtable; int code = sdd["code"].GetJsonConverter().toInt(); NetCode netCode = (NetCode)code; if (NetCode.Success == netCode) { if (sdd.ContainsKey("data")) { object ob = sdd["data"]; Hashtable data = ob as Hashtable; if (null != OnComplete) { OnComplete(data); } } else { if (null != OnComplete) { OnComplete(sdd); } } } else { string msg = ""; if (sdd.ContainsKey("msg")) { msg = sdd["msg"].GetJsonConverter().toStr(); } Debug.LogWarning("Return Error:" + netCode.ToString() + "; msg:" + msg); if (null != OnError) { OnError(netCode, msg); } } } catch (System.Exception e) { Debug.LogWarning("Return Error:" + NetCode.JsonError.ToString() + "; msg:" + e.Message); if (null != OnError) { OnError(NetCode.JsonError, e.Message); } } } }
public bool ClntBufHndl(byte[] buf) { int offs = 0; switch (mState) { case NetCode.Srvr1DatRetriving: if (mBrd.ReadByteSl1(buf, ref offs)) { Dispatcher.InvokeAsync(() => WPopup.s.ShowDialog(Txt.s._[(int)TxI.OP1_DT_NOK])); break; } Dispatcher.InvokeAsync(() => LoadSl()); mState = NetCode.QuestRetrieving; return(true); case NetCode.QuestRetrieving: if (mBrd.ReadByteQPack(buf, ref offs)) { Dispatcher.InvokeAsync(() => WPopup.s.ShowDialog(Txt.s._[(int)TxI.OP1_Q_NOK])); break; } mState = NetCode.AnsKeyRetrieving; return(true); case NetCode.AnsKeyRetrieving: if (mBrd.ReadByteKey(buf, ref offs)) { Dispatcher.InvokeAsync(() => WPopup.s.ShowDialog(Txt.s._[(int)TxI.OP1_KEY_NOK])); break; } else { Dispatcher.InvokeAsync(() => { btnStrt.IsEnabled = true; btnStrt.Foreground = Theme.s._[(int)BrushId.FG]; btnStrt.Background = Theme.s._[(int)BrushId.mConn]; btnConn.IsEnabled = false; btnConn.Foreground = Theme.s._[(int)BrushId.FG_Gray]; btnConn.Background = Theme.s._[(int)BrushId.BG_Gray]; }); } break; case NetCode.SrvrSubmitting: if (buf.Length - offs == 4 && BitConverter.ToInt32(buf, offs) == 1) { //mCbMsg += Txt.s._[(int)TxI.SRVR_SUBMT_OK]; Dispatcher.InvokeAsync(() => { btnSubmit.IsEnabled = false; btnSubmit.Foreground = Theme.s._[(int)BrushId.FG_Gray]; btnSubmit.Background = Theme.s._[(int)BrushId.BG_Gray]; }); } break; } return(false); }
public bool SrvrBufHndl(byte[] buf, out byte[] outMsg) { outMsg = null; int offs = 0; NetCode c = (NetCode)BitConverter.ToInt32(buf, offs); offs += 4; QuestSheet qs; int lvid; ExamineeA e; DateTime dt; switch (c) { case NetCode.Dating: outMsg = new byte[DT.BYTE_COUNT]; offs = 0; DT.ToByte(outMsg, ref offs, mBrd.mDt); return(true); case NetCode.Authenticating: e = new ExamineeS1(); e.bFromC = true; e.ReadByte(buf, ref offs); bool lck = true; bool found = false; foreach (SortedList <int, bool> l in vfbLock) { if (l.TryGetValue(e.LvId, out lck)) { found = true; break; } } if (!found) { lck = false; } if (!lck) { ExamineeA o = null; dt = DateTime.Now; foreach (ExamSlot sl in mBrd.Slots.Values) { if ((o = sl.Signin(e)) != null) { dt = sl.Dt; break; } } if (o != null) { if (o.dtTim1.Hour == DT.INV) { o.dtTim1 = DateTime.Now; } Dispatcher.InvokeAsync(() => { foreach (Op1SlotView vw in tbcSl.Items.OfType <Op1SlotView>()) { TextBlock t; lvid = o.LvId; if (vw.vComp.TryGetValue(lvid, out t)) { t.Text = o.tComp; } if (vw.vDt1.TryGetValue(lvid, out t)) { t.Text = o.dtTim1.ToString("HH:mm"); } CheckBox cbx; if (vw.vLock.TryGetValue(lvid, out cbx)) { cbx.IsChecked = true; cbx.IsEnabled = true; } if (vw.vbLock.Keys.Contains(lvid)) { vw.vbLock[lvid] = true; } } }); byte[] a; o.bFromC = true; o.ToByte(out a); outMsg = new byte[4 + a.Length]; Buffer.BlockCopy(BitConverter.GetBytes(0), 0, outMsg, 0, 4); Buffer.BlockCopy(a, 0, outMsg, 4, a.Length); } else { outMsg = new byte[4]; Buffer.BlockCopy(BitConverter.GetBytes((int)TxI.SIGNIN_NOK), 0, outMsg, 0, 4); return(false); //close } } else { ExamineeA o = null; foreach (ExamSlot sl in mBrd.Slots.Values) { if ((o = sl.Find(e.LvId)) != null) { break; } } if (o == null) { o = new ExamineeC(e.tId); } if (o.tComp == null) { outMsg = new byte[16]; } else { outMsg = new byte[16 + o.tComp.Length]; } Buffer.BlockCopy(BitConverter.GetBytes((int)TxI.SIGNIN_AL), 0, outMsg, 0, 4); if (o.tComp == null) { Buffer.BlockCopy(BitConverter.GetBytes(0), 0, outMsg, 4, 4); offs = 8; } else { byte[] comp = Encoding.UTF8.GetBytes(o.tComp); Buffer.BlockCopy(BitConverter.GetBytes(comp.Length), 0, outMsg, 4, 4); offs = 8; Buffer.BlockCopy(comp, 0, outMsg, offs, o.tComp.Length); offs += comp.Length; } Buffer.BlockCopy(BitConverter.GetBytes(o.dtTim1.Hour), 0, outMsg, offs, 4); offs += 4; Buffer.BlockCopy(BitConverter.GetBytes(o.dtTim1.Minute), 0, outMsg, offs, 4); break; } return(true); case NetCode.ExamRetrieving: outMsg = null; lvid = BitConverter.ToInt32(buf, offs); ExamSlot slo = null; foreach (ExamSlot s in mBrd.Slots.Values) { foreach (ExamRoom r in s.Rooms.Values) { if (r.vExaminee.ContainsKey(lvid)) { slo = s; break; } } } if (slo == null) { outMsg = new byte[4]; Array.Copy(BitConverter.GetBytes((int)TxI.NEEID_NF), 0, outMsg, 0, 4); break; } Level lv = (lvid < (int)Level.MAX_COUNT_EACH_LEVEL) ? Level.A : Level.B; offs += 4; int qsid = BitConverter.ToInt32(buf, offs); if (qsid == (int)Level.MAX_COUNT_EACH_LEVEL) { byte[] a = slo.ToByteNextQS(lv); if (a != null) { outMsg = new byte[a.Length + 4]; Array.Copy(BitConverter.GetBytes(0), outMsg, 4); Array.Copy(a, 0, outMsg, 4, a.Length); } } else if (slo.MainPacks[lv].Sheets.TryGetValue(qsid, out qs)) { outMsg = new byte[qs.ItemsInBytes.Length + 4]; Array.Copy(BitConverter.GetBytes(0), outMsg, 4); Array.Copy(qs.ItemsInBytes, 0, outMsg, 4, qs.ItemsInBytes.Length); } if (outMsg == null) { mCbMsg += Txt.s._[(int)TxI.QS_NFOUND] + (qsid); outMsg = new byte[8]; Array.Copy(BitConverter.GetBytes((int)TxI.QS_NFOUND), 0, outMsg, 0, 4); Array.Copy(BitConverter.GetBytes(qsid), 0, outMsg, 4, 4); } break; case NetCode.Submiting: e = new ExamineeS1(); e.bFromC = true; if (!e.ReadByte(buf, ref offs)) { AnsSheet keySh = null; found = false; foreach (ExamSlot sl in mBrd.Slots.Values) { if (sl.mKeyPack.Sheets.TryGetValue(e.mAnsSh.uQSLvId, out keySh)) { found = true; break; } } if (!found) { outMsg = BitConverter.GetBytes(101); //todo break; } ExamineeA o = null; lvid = e.LvId; found = false; foreach (ExamSlot sl in mBrd.Slots.Values) { if ((o = sl.Find(lvid)) != null) { break; } } if (o != null) { o.eStt = NeeStt.Finished; o.mAnsSh = e.mAnsSh; o.uGrade = keySh.Grade(e.mAnsSh.aAns); o.dtTim2 = DateTime.Now; foreach (SortedList <int, bool> sl in vfbLock) { if (sl.ContainsKey(lvid)) { sl[lvid] = true; } } Dispatcher.InvokeAsync(() => { bool toSubm = true; foreach (Op1SlotView vw in tbcSl.Items.OfType <Op1SlotView>()) { TextBlock t = null; if (vw.vDt2.TryGetValue(lvid, out t)) { t.Text = o.dtTim2.ToString("HH:mm"); } if (vw.vMark.TryGetValue(lvid, out t)) { t.Text = o.Grade.ToString(); } CheckBox cbx; if (vw.vLock.TryGetValue(lvid, out cbx)) { cbx.IsChecked = true; cbx.IsEnabled = false; } if (vw.vAbsen.TryGetValue(lvid, out cbx)) { cbx.IsChecked = cbx.IsEnabled = false; } if (!vw.ToSubmit()) { toSubm = false; } } if (toSubm) { ToSubmit(true); } }); o.ToByte(out outMsg, 0); } else { mCbMsg += Txt.s._[(int)TxI.NEEID_NF] + ' ' + lvid; outMsg = BitConverter.GetBytes((int)TxI.NEEID_NF); } } else { mCbMsg += Txt.s._[(int)TxI.RECV_DAT_ER]; outMsg = BitConverter.GetBytes((int)TxI.RECV_DAT_ER); } break; default: outMsg = null; break; } return(false); }
public override IEnumerator doReauest() { bool hasLoadingPage = Game.UIMgr.IsSceneActive(UIPage.LoadingPage); if (useMask && !hasLoadingPage) { Game.LoadingPage.Show(LoadPageType.OnlyMask); } string url = GlobalConfig.URL_ROOT + uri; if (args == null) { args = new Dictionary <string, string>(); } CheckCommonParam(); WWWForm wwwform = getForm(url); WWW www = new WWW(url, wwwform.data, GetHeader(wwwform)); yield return(www); while (!www.isDone) { yield return(0); } if (www.error == null) { NetCode netCode = NetCode.Unknown; Hashtable sdd = null; string msg = ""; try { string jsons = www.text; // 解密 #if UNITY_IOS || UNITY_IPHONE Debug.Log(url + ": net jsons == " + jsons); #elif UNITY_ANDROID jsons = GetJsonFormXXTea(jsons, url); Debug.Log(url + ": net jsons == " + jsons); #endif sdd = MiniJSON2.jsonDecode(jsons) as Hashtable; int code = sdd["error_code"].GetJsonConverter().toInt(); netCode = (NetCode)code; } catch (System.Exception e) { netCode = NetCode.JsonError; msg = e.Message; } if (NetCode.Success == netCode) { Hashtable data = null; if (sdd.ContainsKey("data")) { object ob = sdd["data"]; data = ob as Hashtable; } if (null != OnComplete) { OnComplete(data); } } else { if (netCode != NetCode.JsonError && null != sdd && sdd.ContainsKey("msg")) { msg = sdd["msg"].GetJsonConverter().toStr(); } Debug.LogWarning("Return Error:" + netCode.ToString() + "; msg:" + msg); if (null != OnError) { OnError(netCode, msg); } } if (useMask && !hasLoadingPage) { Game.LoadingPage.Hide(); } } }
public NetStateMsg ConnectSuccess() { code = NetCode.ConnectSuccess; return(this); }
protected override void Update(GameTime gameTime) { #if true level.getClientPlayer().EntityPacket = new EntityPacket(level.getClientPlayer()); //DIFFERENCE DETECTION float x = 0, y = 0; input.Update(this.IsActive, Mouse.GetState(), Keyboard.GetState(), GamePad.GetState(PlayerIndex.One)); chat.update(); mouseX = (int)input.MousePos.X; mouseY = (int)input.MousePos.Y; if (!chat.Open && !menu.Open) { if (input.KeyDown(Keys.LeftShift)) { level.getClientPlayer().speed = 2; } else { level.getClientPlayer().speed = 1; } if (input.KeyDown(Keys.W)) { y -= level.getClientPlayer().speed; } if (input.KeyDown(Keys.A)) { x -= level.getClientPlayer().speed; } if (input.KeyDown(Keys.S)) { y += level.getClientPlayer().speed; } if (input.KeyDown(Keys.D)) { x += level.getClientPlayer().speed; } y += (int)Math.Round(input.CurrentGamepadState.ThumbSticks.Left.Y) * -1; x += (int)Math.Round(input.CurrentGamepadState.ThumbSticks.Left.X); if (input.KeyPressed(Keys.PageUp)) { time.CurrentTime += 0.1f; } if (input.KeyPressed(Keys.PageDown)) { time.CurrentTime -= 0.1f; } if (input.KeyPressed(Keys.T)) { chat.Open = true; } if (input.KeyPressed(Keys.L)) { if (playerlight) { playerlight = false; } else { playerlight = true; } } } if (input.KeyPressed(Keys.F11)) { if (graphics.IsFullScreen) { graphics.IsFullScreen = false; ChangeResolution(noFullscreenResolutionW, noFullscreenResolutionH); } else { graphics.IsFullScreen = true; noFullscreenResolutionW = screenWidth; noFullscreenResolutionH = screenHeight; ChangeResolution(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height); } } if (input.KeyPressed(Keys.Escape)) { if (chat.Open) { chat.Open = false; } if (menu.Open) { menu.Open = false; } else { menu.Open = true; } } switch (currentGamestate) { case GameState.Running: if (input.CurrentMouseState.ScrollWheelValue > input.PreviousMouseState.ScrollWheelValue && input.KeyDown(Keys.LeftControl)) { camera.AdjustZoom(0.2f); } if (input.CurrentMouseState.ScrollWheelValue < input.PreviousMouseState.ScrollWheelValue && input.KeyDown(Keys.LeftControl)) { camera.AdjustZoom(-0.2f); } level.getClientPlayer().Move(new Vector2(x, y)); camera.CenterOn(new Vector2(level.getClientPlayer().Position.X + level.getClientPlayer().width / 2, level.getClientPlayer().Position.Y + level.getClientPlayer().height / 2), true); inv.Update(input); break; case GameState.Editor: editor.Update(); if (editor.tilesetScroll) { editor.moveTileset(new Vector2(x, y)); } else { camera.MoveCamera(new Vector2(x, y)); } if (editor.currentEditorMode == MapEditor.EditorMode.EntityAdd) { inv.Update(input); } break; case GameState.Pause: break; } level.update(); effectmanager.Update(input); menu.update(); hb.Update(gameTime); sound.update(); NetCode.Update(); //After all movement !important input.UpdatePrev(); #endif base.Update(gameTime); }
public bool SrvrBufHndl(byte[] buf, out byte[] outMsg) { int offs = 0; NetCode c = (NetCode)BitConverter.ToInt32(buf, offs); offs += 4; int x; switch (c) { case NetCode.Srvr1Auth: outMsg = BitConverter.GetBytes((int)TxI.OP_AUTH_NOK); if (buf.Length - offs < 12) { break; } x = BitConverter.ToInt32(buf, offs); offs += 4; string pw = Encoding.ASCII.GetString(buf, offs, 8); offs += 8; foreach (ExamSlot sl in mBrd.vSl.Values) { if (sl.vRoom.ContainsKey(x)) { if (pw == sl.vRoom[x].tPw) { outMsg = BitConverter.GetBytes((int)TxI.OP_AUTH_OK); break; } } } break; case NetCode.Srvr1DatRetriving: if (buf.Length - offs < 4) { outMsg = null; break; } x = BitConverter.ToInt32(buf, offs); offs += 4; outMsg = mBrd.ToByteSl1(x); Dispatcher.InvokeAsync(() => { foreach (Op0SlotView vw in tbcSl.Items.OfType <Op0SlotView>()) { vw.UpRT1(x); } }); return(true); case NetCode.QuestRetrieving: if (buf.Length - offs < 4) { outMsg = null; break; } x = BitConverter.ToInt32(buf, offs); offs += 4; outMsg = mBrd.ToByteQPack(x); return(true); case NetCode.AnsKeyRetrieving: outMsg = mBrd.ToByteKey(); break; case NetCode.SrvrSubmitting: int rid; if (-1 < (rid = mBrd.ReadByteSl0(buf, ref offs))) { string emsg; if (mBrd.DBUpdateRs(rid, out emsg)) { mCbMsg += emsg; } else if (emsg == null) { mCbMsg += Txt.s._[(int)TxI.SRVR_DB_OK]; Dispatcher.InvokeAsync(() => { foreach (Op0SlotView vw in tbcSl.Items.OfType <Op0SlotView>()) { vw.UpdateRsView(rid); } }); } mBrd.DBUpStt(); } outMsg = BitConverter.GetBytes(1); break; default: outMsg = null; break; } return(false); }