示例#1
0
    public void SCreateRole(string name, int imageId)
    {
        CMSG cMsg = new CMSG();

        cMsg.wCmdId = (UInt16)CS_CMD_ID.CS_CREATE_ROLE;
        cMsg.stBody.stCsCreateRole            = new CSCreateRole();
        cMsg.stBody.stCsCreateRole.szRoleName = TDRTools.strToByte(name);
        cMsg.stBody.stCsCreateRole.wImageID   = (ushort)imageId;
        m_serverCeneter.SendAndBack(cMsg);
    }
示例#2
0
    //连接
    private int ConnectInternal()
    {
        int    ret        = 0;
        int    iSerivceID = 123;
        int    iBuffLen   = 1024 * 1024;
        string appid      = "appId123456";

        eAccountType   AccountType = eAccountType.TGCP_ACCOUNT_TYPE_PC_OPENID;
        eEncryptMethod iEncMethod  = eEncryptMethod.TGCP_ENCRYPT_METHOD_AES;
        eKeyMaking     iKeyMode    = eKeyMaking.TGCP_KEY_MAKING_INSVR;

//        if (this.m_loginInfo == null)
//        {
//#if !UNITY_EDITOR
//            m_loginInfo = MSDK.Instance.getLoginRecord();
//            GlobalData.system.SaveLoginRetInfo(m_loginInfo);

//            appid = (PlatformType.Weixin == m_loginInfo.platform) ? NetConfig.wx_appid : NetConfig.qq_appid;
//#endif
//        }

        if (null != m_TgcpHandle)
        {
            Log.info("有旧的tcp handler", "NetConnector.connectInternal");
        }
        m_TgcpHandle = new TGCPAPI();

#if UNITY_STANDALONE_WIN
        m_TgcpHandle.WSAStartUp(2, 0);
#endif

        //switch (this.m_loginInfo.platform)
        //{
        //    case PlatformType.Weixin:
        //        AccountType = eAccountType.TGCP_ACCOUNT_TYPE_WX_OPENID;
        //        break;
        //    case PlatformType.QQ:
        //        AccountType = eAccountType.TGCP_ACCOUNT_TYPE_QQ_OPENID;
        //        break;
        //    case PlatformType.Guest:
        //        AccountType = eAccountType.TGCP_ACCOUNT_TYPE_IOS_GUEST;
        //        break;
        //    default:
        //        Log.info("AccountType 末赋值");
        //        break;
        //}

        Log.info("appid: " + appid);
        Log.info("openid: " + m_openid);
        Log.info("accesstoken: " + "");
        Log.info("AccountType: " + AccountType);
        Log.info("iEncMethod: " + iEncMethod);
        Log.info("iKeyMode: " + iKeyMode);
        Log.info("iSerivceID: " + iSerivceID);

        //if (string.IsNullOrEmpty(m_loginInfo.openid))
        //{
        //    Log.info("openid为空,须重新登录");
        //    //openid为空操作待补
        //    OnOpenIdIsEmptyHandler();
        //    return ret;
        //}
        // 发送更新鉴权信息
        //EventManager.Send(EventType_DataReport.QQ_REPORT_UPDATE_AUTH_INFO, new object[] { accesstoken, openid });

        byte[] byteid    = TDRTools.strToByte(appid);
        byte[] bytetoken = TDRTools.strToByte("access tokey");

        ret = m_TgcpHandle.create_and_init_string(iSerivceID, byteid, byteid.Length, iBuffLen, AccountType, m_openid, bytetoken, bytetoken.Length);
        if (0 != ret)
        {
            Log.info("m_TgcpHandle.create_and_init_string failed: " + ret);
            return(ret);
        }

        ret = m_TgcpHandle.set_security_info(iEncMethod, iKeyMode, "");
        if (0 != ret)
        {
            Log.info("m_TgcpHandle.set_security_info failed: " + ret);
            return(ret);
        }

        ret = m_TgcpHandle.set_refresh_token_expire(0);
        if (0 != ret)
        {
            Log.info("m_TgcpHandle.set_refresh_token_expire failed: " + ret);
            return(ret);
        }

        // #if UNITY_EDITOR
        //         ret = m_TgcpHandle.set_authtype(eAuthType.TGCP_AUTH_NONE);
        // #endif
        //暂时都关闭鉴权
        ret = m_TgcpHandle.set_authtype(eAuthType.TGCP_AUTH_NONE);

        Log.info("m_TgcpHandle init success");

        try
        {
            Log.info("ip: " + m_ipAddress);
            Log.info("port: " + GlobalData.system.serverData.port);
            ret = AsynConnectServer(m_ipAddress, m_port);
            if (0 != ret)
            {
                Log.infoWarning("Could not connect!");
                NotifyDisconnected((TGCP_ERROR)ret);
            }
            Log.info("Net_initConned");
        }
        catch (Exception ex)
        {
            Log.info(ex.ToString());
        }

        return(ret);
    }