Exemplo n.º 1
0
    /// <summary>
    /// 发送ping包
    /// </summary>
    /// <param name="data"></param>
    public void AsyncSendPing()
    {
        IDictionary <string, object> packet = new Dictionary <string, object>();

        packet.Add("msgid", NetProtocol.PING);
        CWritePacket  writePacket = new CWritePacket(NetProtocol.PING);
        StringBuilder builder     = Jsontext.WriteData(packet);
        string        json_Str    = builder.ToString();

        writePacket.WriteString(json_Str);
        m_Client.BeginSend(writePacket.GetPacketByte(), writePacket.GetPacketByte().Length, new AsyncCallback(SendCallback), null);
    }
Exemplo n.º 2
0
    /// <summary>
    /// 登录游戏
    /// </summary>
    /// <param name="cmd"></param>
    /// <param name="parameter"></param>
    public CWritePacket InputLogin(string account)
    {
        IDictionary <string, object> packet = new Dictionary <string, object>();

        packet.Add("msgid", NetProtocol.LOGIN_REQ);
        packet.Add("account", account);
        CWritePacket  writePacket = new CWritePacket(NetProtocol.LOGIN_REQ);
        StringBuilder builder     = Jsontext.WriteData(packet);
        string        json_Str    = builder.ToString();

        writePacket.WriteString(json_Str);
        return(writePacket);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 参加匹配
    /// </summary>
    /// <param name="cmd"></param>
    /// <param name="parameter"></param>
    public CWritePacket InputMatch(int matchType)
    {
        IDictionary <string, object> packet = new Dictionary <string, object>();

        packet.Add("msgid", NetProtocol.MATCH_REQ);
        packet.Add("playerId", GameData.m_CurrentRoleId);
        packet.Add("matchType", matchType);
        CWritePacket  writePacket = new CWritePacket(NetProtocol.MATCH_REQ);
        StringBuilder builder     = Jsontext.WriteData(packet);
        string        json_Str    = builder.ToString();

        writePacket.WriteString(json_Str);
        return(writePacket);
    }
Exemplo n.º 4
0
    /// <summary>
    /// 准备操作
    /// </summary>
    /// <param name="cmd"></param>
    /// <param name="parameter"></param>
    public CWritePacket InputReady()
    {
        IDictionary <string, object> packet = new Dictionary <string, object>();

        packet.Add("msgid", NetProtocol.READY);
        packet.Add("playerId", GameData.m_CurrentRoleId);
        packet.Add("heroId", GameData.m_HeroId);
        packet.Add("mobaKey", GameData.m_MobaKey);
        CWritePacket  writePacket = new CWritePacket(NetProtocol.READY);
        StringBuilder builder     = Jsontext.WriteData(packet);
        string        json_Str    = builder.ToString();

        writePacket.WriteString(json_Str);
        return(writePacket);
    }
Exemplo n.º 5
0
    void Send(Dictionary <string, object> newpacket, CWritePacket packet)
    {
        System.Text.StringBuilder stringbuilder = Jsontext.WriteData(newpacket);
        stringbuilder.Append("\0");

        string json_s = stringbuilder.ToString();

        if (DataDefine.isEFS == 1)
        {
            //加密处理
            json_s = packet.Compress(json_s, DataDefine.datakey);
        }
        packet.WriteString(json_s);
        // Debug.Log( json_s );

        SendPacket(packet, C2SMessageType.Active);
    }
Exemplo n.º 6
0
    protected void PacketDictAndSend(UInt32 msgID, Dictionary <string, object> newpacket, C2SMessageType c2sType = C2SMessageType.PASVWait)
    {
        CWritePacket packet = new CWritePacket(msgID);

        System.Text.StringBuilder stringbuilder = Jsontext.WriteData(newpacket);
        stringbuilder.Append("\0");

        string json_s = stringbuilder.ToString();

        if (DataDefine.isEFS == 1)
        {
            //加密处理
            json_s = packet.Compress(json_s, DataDefine.datakey);
        }
        packet.WriteString(json_s);

        if (DataDefine.isLogMsgDetail)
        {
            Debug.Log("Send msgDetail: " + json_s);
        }

        SendPacket(packet, c2sType);
    }
Exemplo n.º 7
0
    /// <summary>
    /// 输入操作
    /// </summary>
    /// <param name="cmd"></param>
    /// <param name="parameter"></param>
    public CWritePacket InputCmd(Cmd cmd, string parameter = null)
    {
        FrameKeyData frameKeyData = new FrameKeyData();

        frameKeyData.m_KeyDataList = new List <KeyData>();
        KeyData data = new KeyData();

        data.m_RoleId    = GameData.m_CurrentRoleId;
        data.m_Cmd       = (int)cmd;
        data.m_Parameter = parameter;
        frameKeyData.m_KeyDataList.Add(data);
        Dictionary <string, object> packet = new Dictionary <string, object>();

        packet.Add("msgid", NetProtocol.SYNC_KEY);
        packet.Add("roleid", GameData.m_CurrentRoleId);
        packet.Add("mobaKey", GameData.m_MobaKey);
        packet.Add("keydatalist", frameKeyData.m_KeyDataList);
        CWritePacket  writePacket = new CWritePacket(NetProtocol.SYNC_KEY);
        StringBuilder builder     = Jsontext.WriteData(packet);
        string        json_Str    = builder.ToString();

        writePacket.WriteString(json_Str);
        return(writePacket);
    }