public static Protocol Decode(Octets content) { Protocol prtc = null; int iType = 0; OctetsStream os = new OctetsStream(content); OctetsStream data = new OctetsStream(); try { os.Begin(); iType = (int)os.uncompact_uint32(); os.unmarshal(data); os.Commit(); prtc = Create(iType); if (prtc == null) { prtc = new ProtocolDefault(); Debug.Log(string.Format("Protocol type {0} not found", (NetProtocolType)iType)); } else prtc.unmarshal(data); } catch (MarshalException) { os.Rollback(); Debug.Log(string.Format("Protocol decode error, type {0}", (NetProtocolType)iType)); prtc = null; } return prtc; }
public new OctetsStream Clone() { OctetsStream os = new OctetsStream((Octets)base.Clone()); os.pos = pos; os.tranpos = pos; return os; }
public OctetsStream unmarshal(OctetsStream os) { int size = (int)os.uncompact_uint32(); for (int i = 0; i < size; i++) { Add(os.unmarshal_Octets()); } return os; }
public override OctetsStream unmarshal(OctetsStream os) { identity = os.unmarshal_Octets(); userid = os.unmarshal_int(); algo = os.unmarshal_sbyte(); response = os.unmarshal_Octets(); device_info = os.unmarshal_Octets(); return os; }
public override OctetsStream marshal(OctetsStream os) { os.marshal(identity); os.marshal(userid); os.marshal(algo); os.marshal(response); os.marshal(device_info); return os; }
public override OctetsStream marshal(OctetsStream os) { os.marshal(serverList); os.marshal(version); os.marshal(versionList); os.marshal(serverListLength); os.marshal(versionLength); os.marshal(versionListLength); return os; }
public override OctetsStream unmarshal(OctetsStream os) { serverList = os.unmarshal_Octets(); version = os.unmarshal_Octets(); versionList = os.unmarshal_Octets(); serverListLength = os.unmarshal_uint(); versionLength = os.unmarshal_uint(); versionListLength = os.unmarshal_uint(); return os; }
public override OctetsStream marshal(OctetsStream os) { os.marshal(nonce); os.marshal(version); os.marshal(res_version); os.marshal(edition); os.marshal(algo); os.marshal(server_time); return os; }
public override OctetsStream unmarshal(OctetsStream os) { nonce = os.unmarshal_Octets(); version = os.unmarshal_uint(); res_version = os.unmarshal_Octets(); edition = os.unmarshal_Octets(); algo = os.unmarshal_sbyte(); server_time = os.unmarshal_uint(); return os; }
public OctetsStream marshal(OctetsStream os) { Object[] arry = ToArray(); os.compact_uint32((uint)arry.Length); for (int i = 0; i < arry.Length; i++) { os.marshal((Octets)arry[i]); } return os; }
void trySend() { if (++m_tickcount < 60) return; m_tickcount = m_tickcount % 60; IntPtr addr = TssSdk.tss_get_report_data(); if(ECGameSession.Instance().IsConnected == false) return; if (addr != IntPtr.Zero) { IntPtr anti_data = IntPtr.Zero; ushort anti_data_len = 0; if (TssSdk.Is64bit()) { short anti_data_len_temp = Marshal.ReadInt16(addr, 0); Int64 anti_data_temp = Marshal.ReadInt64(addr, 2); anti_data_len = (ushort)anti_data_len_temp; anti_data = new IntPtr(anti_data_temp); } else if (TssSdk.Is32bit()) { short anti_data_len_temp = Marshal.ReadInt16(addr, 0); Int64 anti_data_temp = Marshal.ReadInt32(addr, 2); anti_data_len = (ushort)anti_data_len_temp; anti_data = new IntPtr(anti_data_temp); } if (anti_data != IntPtr.Zero) { byte[] data = new byte[anti_data_len]; Marshal.Copy(anti_data, data, 0, anti_data_len); GNET.Common.OctetsStream os = new GNET.Common.OctetsStream(); os.marshal_long((long)m_roleId); os.marshal(data); int nProtolNum = 8910; CommonData netdata = new CommonData(nProtolNum, os); ECGameSession gs = ECGameSession.Instance(); gs.SendNetData(netdata); TssSdk.tss_del_report_data(addr); } } }
public override OctetsStream unmarshal(OctetsStream os) { m_os = os; return null; }
public bool OnPrtc_Challenge(OctetsStream os) { try { Challenge prtc = new Challenge(); prtc.unmarshal(os); Debug.Log(string.Format("On protocol using C#: {0}", (NetProtocolType)Challenge.PROTOCOL_TYPE)); //检查版本 { LuaDLL.lua_getglobal(wLua.L.L, "OnChallengeCheckVersion"); LuaDLL.lua_pushinteger(wLua.L.L, (Int32)prtc.version); LuaStatic.addGameObject2Lua(wLua.L.L, prtc.res_version, "Octets"); if (wLua.L.PCall(2, 1)) { Boolean bCheckSucc = LuaDLL.lua_toboolean(wLua.L.L, -1); LuaDLL.lua_pop(wLua.L.L, 1); if (!bCheckSucc) { return false; } } else { String errInfo = LuaDLL.lua_tostring(wLua.L.L, -1); LuaDLL.lua_pop(wLua.L.L, 1); Debug.LogWarning("OnChallengeCheckVersion failed: " + errInfo); } } //HMAC_MD5Hash hmac_md5 = new HMAC_MD5Hash(); Octets id = new Octets(UserName); Octets pwd = new Octets(Password); Response p = new Response(); // { // MD5Hash md5 = new MD5Hash(); // md5.Update(id); // md5.Update(pwd); // md5.Final(Nonce); // hmac_md5.SetParameter(Nonce); // // hmac_md5.Update(prtc.nonce); // p.identity = id; // p.userid = 0; // p.algo = prtc.algo; // hmac_md5.Final(p.response); // } //使用token登录 { p.identity = id; p.userid = 0; p.algo = prtc.algo; p.response = pwd; Nonce = pwd; } string strInfo = ECGame.GenerateDeviceInfo(); p.device_info.setString(strInfo); SendNetData(p); } catch (Exception e) { Debug.Log(e.ToString()); } return true; }
public CommonData(int iType, OctetsStream os) : base(iType, 65536, 1) { m_os = os; }
public override OctetsStream marshal(OctetsStream os) { os.push_bytes(m_os.buffer(), m_os.size()); return os; }
internal bool Send(Protocol protocol) { bool osempty = (os.Count == 0); lock(ilock) { OctetsStream o = new OctetsStream(); protocol.Encode(o); if (protocol.SizePolicy(o.size())) { //增加低延迟模式的处理 if(obuffer.size () == 0 && os.Count == 0 && Output(o)) { if(assoc_io != null && assoc_io.channel != null) { //直接发送数据 try { int sentcount = assoc_io.channel.Send(obuffer.buffer(), obuffer.size(), SocketFlags.None); if (sentcount > 0) { obuffer.erase(0, sentcount); return true; } } catch (Exception e) { obuffer.clear(); UnityEngine.Debug.LogWarning(e.StackTrace); UnityEngine.Debug.LogWarning(e.Message); } } } else { os.AddLast(o); if (osempty) { osempty = false; } need_wakeup = true; } return true; } } return false; }
public override OctetsStream unmarshal(OctetsStream os) { return os; }
public static OctetsStream wrap(Octets o) { OctetsStream os = new OctetsStream(); os.swap(o); return os; }
public static int ReadProtocol(IntPtr L) { if (proto_br == null) { UnityEngine.Debug.LogError("proto_br == null"); return 0; } int type = proto_br.ReadInt32(); int datalen = proto_br.ReadInt32(); byte[] data = proto_br.ReadBytes(datalen); OctetsStream os = new OctetsStream(); os.replace(data); GNET.CommonData proto = new GNET.CommonData(type, os); LuaStatic.addGameObject2Lua(L, proto, "userdata"); LuaDLL.lua_pushinteger(L, type); return 2; }
public Octets Encode () { OctetsStream os = new OctetsStream (); Encode(os); return os; }
public static int ReportProtocolRecord(IntPtr L) { string path = EntryPoint.Instance.AssetsPath + "/protocol.dat"; FileStream fs = File.Open(path, FileMode.Open, FileAccess.Read); if (fs == null) { LuaDLL.lua_pushnil(L); return 1; } BinaryReader br = new BinaryReader(fs); br.ReadInt32(); br.ReadSingle(); br.ReadSingle(); br.ReadSingle(); br.ReadSingle(); br.ReadSingle(); br.ReadSingle(); int framecount = 0; StringBuilder sb = new StringBuilder(100000000); while (true) { int rc_type = br.ReadInt32(); if (rc_type == 0) { if (fs.Position != fs.Length) Debug.LogError("wrong proto file"); break; } else if (rc_type == 1) { int type = br.ReadInt32(); int datalen = br.ReadInt32(); byte[] data = br.ReadBytes(datalen); float protime = br.ReadSingle(); OctetsStream os = new OctetsStream(); os.replace(data); GNET.CommonData proto = new GNET.CommonData(type, os); if (type == 34) { Octets oc = proto.GetData().unmarshal_Octets(); MemoryStream mms = new MemoryStream(oc.buffer(), 0, oc.size()); BinaryReader br2 = new BinaryReader(mms); UInt16 cmd_type = br2.ReadUInt16(); sb.Append(string.Format(" cmd = {0} time = {1}", cmd_type, (int)(protime * 1000))); sb.Append("\r\n"); } else { if (type == 502) { sb.Append(string.Format(" ds = {0} time = {1}", proto.GetData().unmarshal_ushort(), (int)(protime * 1000))); sb.Append("\r\n"); } else { sb.Append(string.Format(" pro = {0} time = {1}", type, (int)(protime * 1000))); sb.Append("\r\n"); } } } else if (rc_type == 2) { float frametime = br.ReadSingle(); sb.Append(string.Format("frame {0} time = {1}", framecount++, (int)(frametime * 1000))); sb.Append("\r\n"); } else if (rc_type == 3) { br.ReadSingle(); br.ReadSingle(); br.ReadSingle(); } else { br.ReadSingle(); br.ReadSingle(); br.ReadSingle(); br.ReadSingle(); br.ReadSingle(); br.ReadSingle(); } } File.WriteAllText(EntryPoint.Instance.AssetsPath + "/protolog.txt", sb.ToString()); return 0; }
public override OctetsStream unmarshal(OctetsStream os) { code = os.unmarshal_sbyte(); return os; }
public override OctetsStream marshal(OctetsStream os) { os.marshal(roleid); os.marshal(localsid); return os; }
internal void Encode(OctetsStream os) { os.compact_uint32((uint)getProtocolType()).marshal(new OctetsStream().marshal(this)); }
public override OctetsStream marshal(OctetsStream os) { os.marshal(data); return os; }
public abstract OctetsStream unmarshal(OctetsStream os);
public override OctetsStream unmarshal(OctetsStream os) { data = os.unmarshal_Octets(); localsid = os.unmarshal_uint(); return os; }
public bool OnPrtc_KeyExchange(OctetsStream os) { KeyExchange prtc = new KeyExchange(); prtc.unmarshal(os); Debug.Log(string.Format("On protocol using C#: {0}", (NetProtocolType)KeyExchange.PROTOCOL_TYPE)); //Octets outKey = new Octets(); //ECGameSession GameSession = ECGameSession.Instance(); //outKey = GenerateKey(Nonce, prtc.nonce, outKey); //NetMan.SetOSecurity(NetMan.GetSession(), "ARCFOURSECURITY", outKey); GNET.Common.Security.Security random = GNET.Common.Security.Security.Create("RANDOM"); random.Update(prtc.nonce.resize(16)); Octets inKey = new Octets(); inKey = GenerateKey(Nonce, prtc.nonce, inKey); NetMan.SetISecurity(NetMan.GetSession(), "DECOMPRESSSECURITY", inKey); SendNetData(prtc); return true; }
public override OctetsStream unmarshal(OctetsStream os) { roleid = os.unmarshal_long(); localsid = os.unmarshal_uint(); return os; }
public override OctetsStream unmarshal(OctetsStream os) { nonce = os.unmarshal_Octets(); return os; }