コード例 #1
0
ファイル: ShortConnect.cs プロジェクト: vbetter/Network
    byte[] BuildMsgPack(ShortNetPack sendPack)
    {
        System.IO.MemoryStream stream       = new System.IO.MemoryStream();
        System.IO.BinaryWriter binaryWriter = new System.IO.BinaryWriter(stream);

        // 创建包头
        protocol.Header header = new protocol.Header();
        header.seq           = ProtocolDGlUtility.GetNextSequeue();
        header.sessionid     = LoginMgr.Instance.Roleid.ToString();
        header.roleid        = LoginMgr.Instance.Roleid;
        header.uid           = LoginMgr.Instance.s_uid;
        header.msg_full_name = sendPack.Name;

        // 写入包头
        stream.Position = sizeof(uint) * 2;
        //ProtoBuf.Serializer.Serialize(stream, header);
        uint headerLength = (uint)(stream.Length - sizeof(uint) * 2);

        // 写入包体
        binaryWriter.Write(sendPack.GetBytes());
        uint totalLength = (uint)stream.Length;

        // 写入长度
        stream.Position = 0;
        binaryWriter.Write(totalLength);
        binaryWriter.Write(headerLength);
        binaryWriter.Flush();

        byte[] result = stream.ToArray();
        return(result);
    }
コード例 #2
0
    //发送ping,在第一次角色登录成功后
    public void SendPing()
    {
        return;//暂不需要ping

        m_fLastPingTime = Time.time;
        var ping = new CS.P();

        net.DGPKG sendSMG = ProtocolDGlUtility.BuildDGMsg(ping);
        Network.Instance.SendCSLoginMsg(ref sendSMG, OnPingRsp);
        Debuger.Log("Send Ping : " + Time.time);
    }
コード例 #3
0
    /// <summary>
    /// 发送重连请求
    /// </summary>
    void ReConnReq(CSMsgDelegate callback)
    {
        // 保证加密解密开关是关闭的
        LoginMgr.Instance.ToggleGameServerMsgFilter(false);

        var Req = new ReconnectReq();

        Req.uid   = s_uid;
        Req.gcode = gcode;
        DGPKG msg = ProtocolDGlUtility.BuildDGMsg(Req);

        Network.Instance.SendCSLoginMsg(ref msg, callback);
    }