public object UserLoginSucceedAck(byte[] data) { Proto.ByteArray ba = new Proto.ByteArray(data); Proto.user_snapshot snapshot = Proto.user_snapshot.UnPack(ba); ba.Dispose(); return(snapshot.uid); }
// 游客信息 public object UserLoginSucceedAck(byte[] data) { Proto.ByteArray ba = new Proto.ByteArray(data); Proto.user_snapshot snapshot = Proto.user_snapshot.UnPack(ba); ba.Dispose(); Debug.Log("Welcome userid: " + snapshot.uid); return(null); }
// 游客信息 public object UserLoginSucceedAck(byte[] data) { Proto.ByteArray ba = new Proto.ByteArray(data); Proto.user_snapshot snapshot = Proto.user_snapshot.UnPack(ba); ba.Dispose(); Debug.Log("Welcome userid: " + snapshot.uid); return null; }
// 服务器返回密钥并加密连接 public object GetSeedAck(byte[] data) { Proto.ByteArray ba = new Proto.ByteArray(data); Proto.seed_info si = Proto.seed_info.UnPack(ba); ba.Dispose(); // 启用加密通讯 NetCore.Instance.Encrypt(si.client_send_seed, si.client_receive_seed); return(null); }
// 服务器返回密钥并加密连接 public object GetSeedAck(byte[] data) { Proto.ByteArray ba = new Proto.ByteArray(data); Proto.seed_info si = Proto.seed_info.UnPack(ba); ba.Dispose(); // 启用加密通讯 NetCore.Instance.Encrypt(si.client_send_seed, si.client_receive_seed); return null; }
// 服务器返回公钥 public object KeyExchangeAck(byte[] data) { Proto.ByteArray ba = new Proto.ByteArray(data); Proto.seed_info si = Proto.seed_info.UnPack(ba); ba.Dispose(); // 启用加密通讯 NetCore.Instance.Encrypt(si.client_send_seed, si.client_receive_seed); // for testing action input return(si); }
// 服务器返回公钥 public object KeyExchangeAck(byte[] data) { Proto.ByteArray ba = new Proto.ByteArray(data); Proto.seed_info si = Proto.seed_info.UnPack(ba); ba.Dispose(); // 启用加密通讯 NetCore.Instance.Encrypt(si.client_send_seed, si.client_receive_seed); // for testing action input return si; }
public object UserLoginSucceedAck(byte[] data) { Proto.ByteArray ba = new Proto.ByteArray(data); Proto.user_snapshot snapshot = Proto.user_snapshot.UnPack(ba); ba.Dispose(); return snapshot.uid; }
// 发送数据包 public void Send(NetProto.Proto.NetBase packet) { NetProto.Proto.ByteArray ba = new NetProto.Proto.ByteArray(); packet.Pack(ba); byte[] data = ba.Data(); ba.Dispose(); Int16 id = packet.NetMsgId; seqid++; UInt16 payloadSize = 6; // sizeof(seqid) + sizeof(opcode) if (data != null) { if (data.Length > UInt16.MaxValue - 6) { Debug.LogError(data.Length + " > UInt16.MaxValue-6"); return; } payloadSize += (UInt16)data.Length; } // payload byte[] payload = new byte[payloadSize]; // seqid Byte[] _seqid = BitConverter.GetBytes(seqid); if (BitConverter.IsLittleEndian) { Array.Reverse(_seqid); } _seqid.CopyTo(payload, 0); // opcode Byte[] _opcode = BitConverter.GetBytes(id); if (BitConverter.IsLittleEndian) { Array.Reverse(_opcode); } _opcode.CopyTo(payload, 4); // data if (data != null) { data.CopyTo(payload, 6); } // try encrypt byte[] encrypted = EncryptStream(payload); // =>pack byte[] buffer = new byte[2 + payloadSize]; // sizeof(header) + payloadSize // =>header Byte[] _header = BitConverter.GetBytes(payloadSize); if (BitConverter.IsLittleEndian) { Array.Reverse(_header); } _header.CopyTo(buffer, 0); // =>payload encrypted.CopyTo(buffer, 2); if (socket.Connected) { socket.BeginSend(buffer, 0, buffer.Length, 0, new AsyncCallback(SendCallback), socket); } }
public override void Pack(ByteArray w) { }
public override void Pack(ByteArray w) { w.WriteUnsignedInt(this.id); }
public override void Pack(ByteArray w) { w.WriteUTF(this.id); }
public override void Pack(ByteArray w) { w.WriteUTF(this.name); w.WriteUTF(this.timeStr); w.WriteUTF(this.msg); }
public override void Pack(ByteArray w) { w.WriteUTF(this.account); w.WriteUTF(this.password); }
public static null_struct UnPack(ByteArray reader) { null_struct tbl = new null_struct(); return(tbl); }
// 发送数据包 public void Send(NetProto.Api.ENetMsgId msgId, NetProto.Proto.NetBase packet) { Int16 id = (Int16)msgId; seqId++; UInt16 payloadSize = 6; // sizeof(seqid) + sizeof(msgid) byte[] data = null; if (packet != null) { NetProto.Proto.ByteArray ba = new NetProto.Proto.ByteArray(); packet.Pack(ba); data = ba.Data(); ba.Dispose(); if (data.Length > UInt16.MaxValue - 6) { Debug.LogError(data.Length + " > UInt16.MaxValue-6"); return; } payloadSize += (UInt16)data.Length; } if (_beforeSendHook != null) { _beforeSendHook(msgId, data); } // payload byte[] payload = new byte[payloadSize]; // seqid Byte[] _seqid = BitConverter.GetBytes(seqId); if (BitConverter.IsLittleEndian) { Array.Reverse(_seqid); } _seqid.CopyTo(payload, 0); // opcode Byte[] _opcode = BitConverter.GetBytes(id); if (BitConverter.IsLittleEndian) { Array.Reverse(_opcode); } _opcode.CopyTo(payload, 4); // data if (data != null) { data.CopyTo(payload, 6); } // try encrypt byte[] encrypted = EncryptStream(payload); // =>pack byte[] buffer = new byte[2 + payloadSize]; // sizeof(header) + payloadSize // =>header Byte[] _header = BitConverter.GetBytes(payloadSize); if (BitConverter.IsLittleEndian) { Array.Reverse(_header); } _header.CopyTo(buffer, 0); // =>payload encrypted.CopyTo(buffer, 2); sendDone.Reset(); try { socket.BeginSend(buffer, 0, buffer.Length, 0, new AsyncCallback(SendCallback), socket); } catch (Exception e) { // 如果socket已经断了,报这个异常 // System.Net.Sockets.SocketException: The socket is not connected Debug.Log(e.ToString()); } }
public abstract void Pack(ByteArray w);