Exemplo n.º 1
0
        public bool ChooseRole(string role_name)
        {
            if (role_name == null)
            {
                LogSystem.LogError("Role Name Is Empty!");
                return(false);
            }

            if (0 == role_name.Length)
            {
                LogSystem.Log("sendChooseRole packet role name is empty!");
                return(false);
            }

            byte[] name = new byte[ServerInfo.ROLENAME_MAX_LENGTH * 2 + 1];
            Array.Copy(System.Text.Encoding.Default.GetBytes(role_name), name, role_name.Length);

            StoreArchive ar = StoreArchive.Load(m_buffer, m_buffer.Length);

            ar.WriteInt8(GlobalClineMsgId.CLIENT_CHOOSE_ROLE);//消息ID

            //unsigned short wsName[OUTER_OBJNAME_LENGTH + 1];	// 名称
            //unsigned char nVerify[16];							// 校验码
            //char strInfo[1];

            ar.WriteUnicodeLen(role_name, (ServerInfo.ROLENAME_MAX_LENGTH + 1) * 2);//玩家名
            byte[] verify = new byte[16];

            fxVerify.GetChooseRoleVerify(role_name, ref verify);
            ar.WriteUserDataNoLen(verify); //检验码
            ar.WriteInt8(0);               //附加信息
            return(m_sender.Send(ar.GetData(), ar.GetLength()));
        }
Exemplo n.º 2
0
        public int GetRecordCols(string name)
        {
            int nCols = 0;

            if (name == null || name.Length == 0)
            {
                LogSystem.Log("Error:GameObject.GetRecordCols name para is emtpy");
                return(nCols);
            }

            try
            {
                if (!mRecordSet.ContainsKey(name))
                {
                    LogSystem.Log("Error:GameObject.GetRecordCols does not exist record:", name);
                    return(nCols);
                }

                GameRecord record = mRecordSet[name];
                if (record != null)
                {
                    nCols = record.GetColcount();
                }
            }
            catch (Exception ex)
            {
                LogSystem.Log("Error:GameObject.GetRecordCols Exception :", ex.ToString());
                return(nCols);
            }
            return(nCols);
        }
Exemplo n.º 3
0
        public bool DeleteRole(string role_name)
        {
            if (role_name == null)
            {
                LogSystem.LogError("Role Name Is Empty!");
                return(false);
            }

            if (0 == role_name.Length)
            {
                LogSystem.Log("DeleteRole  role name is empty!");
                return(false);
            }


            byte[] name = new byte[ServerInfo.ROLENAME_MAX_LENGTH * 2 + 1];
            Array.Copy(System.Text.Encoding.Default.GetBytes(role_name), name, role_name.Length);

            StoreArchive ar = StoreArchive.Load(m_buffer, m_buffer.Length);

            ar.WriteInt8(GlobalClineMsgId.CLIENT_DELETE_ROLE);//消息ID

            //unsigned short wsName[OUTER_OBJNAME_LENGTH + 1];	// 名称

            ar.WriteUnicodeLen(role_name, (ServerInfo.ROLENAME_MAX_LENGTH + 1) * 2);//玩家名
            return(m_sender.Send(ar.GetData(), ar.GetLength()));
        }
Exemplo n.º 4
0
        public bool Custom(ref VarList args)
        {
            StoreArchive ar = StoreArchive.Load(m_buffer, m_buffer.Length);


            int iCount = args.GetCount();

            if (!AddMsgVarList(ref ar, ref args, 0, iCount))
            {
                return(false);
            }
            Array.Clear(varifyCustom, 0, varifyCustom.Length);
            fxVerify.GetCustomVerify(mCustomIndex, iCount, ar.GetData(), ar.GetLength(), ref varifyCustom);

            ar = StoreArchive.Load(m_buffer, m_buffer.Length);

            ar.WriteInt8(GlobalClineMsgId.CLIENT_CUSTOM); //消息ID
            ar.WriteUserDataNoLen(varifyCustom);          //校验码

            ar.WriteInt32(mCustomIndex++);
            ar.WriteInt16(iCount);

            if (!AddMsgVarList(ref ar, ref args, 0, iCount))
            {
                LogSystem.Log("add para error");
                return(false);
            }
            return(m_sender.Send(ar.GetData(), ar.GetLength()));
        }
Exemplo n.º 5
0
        public int GetPropType(string name)
        {
            int type = 0;

            if (name == null || name.Length == 0)
            {
                LogSystem.Log("Error:GameObject.GetPropType name para is emtpy");
                return(type);
            }

            try
            {
                if (!mPropSet.ContainsKey(name))
                {
                    LogSystem.Log("Error:GameObject.GetPropType does not exist property:", name);
                    return(type);
                }
                GameProperty property = mPropSet[name];
                type = property.ValueType;
            }
            catch (Exception ex)
            {
                LogSystem.Log("Error:GameObject.GetPropType Exception :", ex.ToString());
                return(type);
            }
            return(type);
        }
Exemplo n.º 6
0
        public bool QueryRecordObject(string name, int row, int col, ref ObjectID oResult)
        {
            try
            {
                if (!mRecordSet.ContainsKey(name))
                {
                    return(false);
                }

                GameRecord record = mRecordSet[name];
                if (record == null)
                {
                    return(false);
                }
                Var result = Var.zero;

                if (!record.GetValue(row, col, ref result))
                {
                    return(false);
                }
                oResult = result.GetObject();
            }
            catch (Exception ex)
            {
                LogSystem.Log("Error:GameObject.QueryRecord Exception :", ex.ToString());
            }
            return(true);
        }
Exemplo n.º 7
0
    public static bool ConnecToMember(string strServerIP, int iPort, string strUserName, string strPassword, string strValidatestring = "", int iReconnect = 2)
    {
        Game game = Game.Instance;

        if (game == null || game.mGameSock == null)
        {
            LogSystem.Log("Error!! ConnectState::ConnectTo (game or game.mGameSock) is null");
            return(false);
        }

        UserLoginClear();

        if (game.mGameSock.Connect(strServerIP, iPort))
        {
            Fm_ClientNet.fxVerify.SetLoginInfo(strServerIP, iPort);
            mstrServer         = strServerIP;
            miPort             = iPort;
            mstrUser           = strUserName;
            mstrPsd            = strPassword;
            mstrValidateString = strValidatestring;
            mbLoginReconnect   = iReconnect > 0;

            return(true);
        }

        return(false);
    }
Exemplo n.º 8
0
 public bool UpdateProperty(ref string name, Var val)
 {
     try
     {
         if (mPropSet == null)
         {
             return(false);
         }
         GameProperty gameProp = GameProperty.zero;
         gameProp.setPropValue(val);
         if (!mPropSet.ContainsKey(name))
         {
             mPropSet.Add(name, gameProp);
         }
         else
         {
             mPropSet[name] = gameProp;
         }
     }
     catch (Exception ex)
     {
         LogSystem.Log("Error,GameObject.UpdateProperty Exception:", ex.ToString());
         return(false);
     }
     return(true);
 }
Exemplo n.º 9
0
        // 资源回调
        private void Handle_Completed(AssetOperationHandle obj)
        {
            TextAsset temp = _handle.AssetObject as TextAsset;

            if (temp != null)
            {
                try
                {
                    SecurityParser sp = new SecurityParser();
                    sp.LoadXml(temp.text);
                    _xml = sp.ToXml();

                    // 解析数据
                    if (_xml != null)
                    {
                        ParseData();
                    }
                }
                catch (Exception ex)
                {
                    LogSystem.Log(ELogType.Error, $"Failed to parse xml {Location}. Exception : {ex.ToString()}");
                }
            }

            // 注意:为了节省内存这里立即释放了资源
            if (_assetRef != null)
            {
                _assetRef.Release();
                _assetRef = null;
            }

            _userCallback?.Invoke();
        }
Exemplo n.º 10
0
    public override void OnUpdate()
    {
        base.OnUpdate();

        if (m_isClosed)
        {
            m_isClosed = false;
            UIViewManager.Instance.CloseReconnectView();

            if (m_SocketClient.onConnectComplete != null)
            {
                LogSystem.Log("连接服务器失败");
                m_SocketClient.onConnectComplete(false);
                m_SocketClient.onConnectComplete = null;
            }
            else
            {
                LogSystem.Log("网络连接断开");
                if (m_SocketClient.OnDisConnect != null)
                {
                    m_SocketClient.OnDisConnect(m_SocketClient.isActiveClose);
                }
            }

            ChangeState(SocketClient.SocketState.Idle);
        }
    }
Exemplo n.º 11
0
        // 资源回调
        private void Handle_Completed(AssetOperationHandle obj)
        {
            try
            {
                TextAsset txt = _handle.AssetObject as TextAsset;
                if (txt != null)
                {
                    // 解析数据
                    ParseDataInternal(txt.bytes);
                }
            }
            catch (Exception ex)
            {
                LogSystem.Log(ELogType.Error, $"Failed to parse config {Location}. Error : {ex.ToString()}");
            }

            // 注意:为了节省内存这里立即释放了资源
            if (_assetRef != null)
            {
                _assetRef.Release();
                _assetRef = null;
            }

            _userCallback?.Invoke(this);
        }
Exemplo n.º 12
0
    /// <summary>
    /// 设置文言信息
    /// </summary>
    /// <param name="strWords"></param>
    public static void SetWordsInfo(string strWords)
    {
        if (string.IsNullOrEmpty(strWords))
        {
            return;
        }

        string[] strLines = strWords.Split(new string[] { "\r\n" }, System.StringSplitOptions.RemoveEmptyEntries);;
        for (int i = 0; i < strLines.Length; i++)
        {
            string[] split = strLines[i].Split(new string[] { "=" }, 2, System.StringSplitOptions.RemoveEmptyEntries);
            if (split.Length == 2)
            {
                if (mWordsDict.ContainsKey(split[0]))
                {
                    LogSystem.Log("the key is echo in local file!!! please check the key = ", split[0]);
                }
                else
                {
                    split[1]             = split[1].Replace("[n]", "\n");
                    mWordsDict[split[0]] = split[1];
                }
            }
        }
    }
Exemplo n.º 13
0
        /// <summary>
        /// 处理连接请求
        /// </summary>
        private void ProcessConnected(object obj)
        {
            TChannel             channel = null;
            SocketAsyncEventArgs e       = obj as SocketAsyncEventArgs;
            UserToken            token   = (UserToken)e.UserToken;

            if (e.SocketError == SocketError.Success)
            {
                // 创建频道
                channel = new TChannel();
                channel.InitChannel(e.ConnectSocket, token.PackageParseType);

                // 加入到频道列表
                lock (_allChannels)
                {
                    _allChannels.Add(channel);
                }
            }
            else
            {
                LogSystem.Log(ELogType.Error, $"ProcessConnected error : {e.SocketError}");
            }

            // 回调函数
            if (token.Callback != null)
            {
                token.Callback.Invoke(channel, e.SocketError);
            }
        }
Exemplo n.º 14
0
        protected override bool OnPrepare(UnityEngine.Object mainAsset)
        {
            if (base.OnPrepare(mainAsset) == false)
            {
                return(false);
            }

            try
            {
                TextAsset temp = mainAsset as TextAsset;
                if (temp == null)
                {
                    return(false);
                }

                // 解析数据
                ParseDataInternal(temp.bytes);
            }
            catch (Exception ex)
            {
                LogSystem.Log(ELogType.Error, $"Failed to parse config {ResName}. Error : {ex.ToString()}");
                return(false);
            }

            // 注意:为了节省内存这里立即释放了资源
            UnLoad();

            return(true);
        }
Exemplo n.º 15
0
        public bool AddRecord2Set(string name, ref GameRecord record)
        {
            try
            {
                if (name == null || name.Length == 0)
                {
                    LogSystem.Log("name is null");
                    return(false);
                }

                if (record == null)
                {
                    LogSystem.Log("record is null");
                    return(false);
                }

                if (mRecordSet.ContainsKey(name))
                {
                    return(false);
                }

                mRecordSet.Add(name, record);
                //test begin
                //test end
            }
            catch (Exception ex)
            {
                LogSystem.Log("Exception:", ex.ToString());
                return(false);
            }
            return(true);
        }
Exemplo n.º 16
0
            /// <summary>
            /// 连接
            /// </summary>
            /// <param name="ar"></param>
            public static void Connect(IAsyncResult ar)
            {
                TextSock self = (TextSock)ar.AsyncState;

                if (self.m_State == SockState.Idle)
                {
                    return;
                }
                try
                {
                    self.m_Socket.EndConnect(ar);
                }
                catch (SocketException e)
                {
                    LogSystem.Log("SocketException e");
                    self.SetSockError(e.ErrorCode, e.ToString());
                    self.ConnectFail();
                    return;
                }
                catch (Exception e)
                {
                    LogSystem.Log("Exception e", e.ToString());
                    return;
                }
                self.StopConnect();
            }
Exemplo n.º 17
0
        public override IEnumerator DownLoad()
        {
            // Check fatal
            if (LoadState != EWebLoadState.None)
            {
                throw new Exception($"Web data download state is not none state. {URL}");
            }

            LoadState = EWebLoadState.Loading;

            // 下载文件
            CacheRequest = new UnityWebRequest(URL, UnityWebRequest.kHttpVerbGET);
            DownloadHandlerBuffer handler = new DownloadHandlerBuffer();

            CacheRequest.downloadHandler = handler;
            CacheRequest.disposeDownloadHandlerOnDispose = true;
            CacheRequest.timeout = ResDefine.WebRequestTimeout;
            yield return(CacheRequest.SendWebRequest());

            // Check error
            if (CacheRequest.isNetworkError || CacheRequest.isHttpError)
            {
                LogSystem.Log(ELogType.Warning, $"Failed to download web data : {URL} Error : {CacheRequest.error}");
                LoadState = EWebLoadState.LoadFailed;
            }
            else
            {
                LoadState = EWebLoadState.LoadSucceed;
            }

            // Invoke callback
            LoadCallback?.Invoke(this);
        }
Exemplo n.º 18
0
        public bool FindRecord(string name)
        {
            if (name == null || name.Length == 0)
            {
                return(false);
            }

            try
            {
                if (!mRecordSet.ContainsKey(name))
                {
                    return(false);
                }

                GameRecord record = mRecordSet[name];
                if (record != null)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                LogSystem.Log("GameObject.FindRecord Exception :", ex.ToString());
                return(false);
            }
            return(false);
        }
Exemplo n.º 19
0
    /// <summary>
    /// 停止UI音效
    /// </summary>
    /// <param name="type"></param>
    public void StopUIAudio(string comName)
    {
        if (!GlobalData.AudioOpen)
        {
            return;
        }

        string    goName    = "UIAudio:" + comName;
        Transform transform = gameObject.transform.Find(goName);

        if (transform == null)
        {
            return;
        }

        AudioSource audioSource = transform.gameObject.GetComponent <AudioSource>();

        if (audioSource == null)
        {
            LogSystem.Log("停止UI音效,音效对象不存在音源组件");

            return;
        }

        audioSource.Stop();

        Destroy(transform.gameObject);
    }
Exemplo n.º 20
0
        public Var QueryRecord(string name, int row, int col)
        {
            Var result = Var.zero;

            try
            {
                if (!mRecordSet.ContainsKey(name))
                {
                    return(result);
                }

                GameRecord record = mRecordSet[name];
                if (record == null)
                {
                    return(result);
                }

                if (!record.GetValue(row, col, ref result))
                {
                    LogSystem.Log("Error,GameObject.QueryRecord GetValue Failed");
                }
            }
            catch (Exception ex)
            {
                LogSystem.Log("Error:GameObject.QueryRecord Exception :", ex.ToString());
            }

            return(result);
        }
Exemplo n.º 21
0
            /// <summary>
            /// 发送
            /// </summary>
            /// <param name="ar"></param>
            public static void Send(IAsyncResult ar)
            {
                TextSock self = (TextSock)ar.AsyncState;

                if (self.m_State == SockState.Idle)
                {
                    return;
                }
                int size;

                try
                {
                    size = self.m_Socket.EndSend(ar);
                    LogSystem.Log("TextSock EndSend", size);
                }
                catch (SocketException e)
                {
                    self.SetSockError(e.ErrorCode, e.ToString());
                    return;
                }
                catch (Exception)
                {
                    return;
                }
            }
Exemplo n.º 22
0
 /// <summary>
 /// 捕获异常错误
 /// </summary>
 public void HandleError(bool isDispose, string error)
 {
     LogSystem.Log(ELogType.Error, error);
     if (isDispose)
     {
         Dispose();
     }
 }
Exemplo n.º 23
0
    /// <summary>
    /// 服务器返回错误消息
    /// </summary>
    /// <param name="obj"></param>
    private void OnServerError(byte[] obj)
    {
        UIViewManager.Instance.CloseWait();
        OP_SYS_ERROR proto = OP_SYS_ERROR.decode(obj);

        LogSystem.Log(proto.code + "   " + proto.msg);
        UIViewManager.Instance.ShowMessage("提示", proto.msg);
    }
Exemplo n.º 24
0
            public void Dispose()
            {
                m_fAfterAlloc = GC.GetTotalMemory(true);

                m_fTotalMemoryAlloc = (float)(m_fAfterAlloc - m_fBeforeAlloc);

                LogSystem.Log(m_szMessage + ": " + (m_fTotalMemoryAlloc) + " bytes ", false);
            }
Exemplo n.º 25
0
    /* @brief:网络中断回调
     * @param: args 回调参数列表
     * @return void
     */
    public static void on_close(VarList args)
    {
        //Debug.Log("on_close" + mbConnected + " " + isChangeRole);
        if (!mbConnected || isChangeRole)
        {
            return;
        }

        ///被顶下线不重连
        if (LoginStage.miErrorCode == 21006)
        {
            return;
        }

        if (mbTryingConnect)
        {
            return;
        }

        mbTryingConnect = true;

        //Debug.Log("on_close " + mbLoginSuccess);
        if (mbLoginSuccess && ObjectManager.mRole != null)
        {
            mbNeedReConnect = true;
            Game game = Game.Instance;
            if (game == null || game.mGameSock == null)
            {
                LogSystem.Log("Error!! ConnectState::on_connect_fail (game or game.mGameSock) is null");
                return;
            }
            //Debug.Log("on_close game.mbPaused" + game.mbPaused);
            if (!game.mbPaused)
            {
                OnNetBlockOrClose();
            }
        }
        else if (mbLoginSuccess)
        {
            ///显示网络已经断线,普通情况
            string strHeader  = TextManager.Instance.GetString("UI00031");
            string strContext = TextManager.Instance.GetString("NetClose");
            if (!string.IsNullOrEmpty(strHeader) && !string.IsNullOrEmpty(strContext))
            {
//                 if (GUIManager.HasView<SystemPrompt>())
//                 {
//                     GUIManager.HideView<SystemPrompt>("SystemPrompt");
//                 }
//                 PromptType pt = PoolManager.PopObject<PromptType>(PoolManager.PoolKey.Object_PromptType);
//                 pt.layer = 5;
//                 pt.title = strHeader;
//                 pt.content = strContext;
//                 pt.style = PromptType.Style.OK;
//                 pt.callback_ok = OnClosePromptOk;
//                 GUIManager.ShowView<SystemPrompt>(pt);
            }
        }
    }
Exemplo n.º 26
0
 public void OnUpdate()
 {
     while (true)
     {
         if (m_ReceiveCount < 5)
         {
             ++m_ReceiveCount;
             lock (m_ReceiveQueue)
             {
                 if (m_ReceiveQueue.Count > 0)
                 {
                     byte[] buffer          = m_ReceiveQueue.Dequeue();
                     byte[] protocodeBuffer = new byte[4];
                     byte[] protoContent    = new byte[buffer.Length - 5];
                     bool   isCompress      = false;
                     using (MemoryStreamExt ms = new MemoryStreamExt(buffer))
                     {
                         isCompress = ms.ReadBool();
                         ms.Read(protocodeBuffer, 0, protocodeBuffer.Length);
                         Array.Reverse(protocodeBuffer);
                         int protoCode = BitConverter.ToInt32(protocodeBuffer, 0);
                         LogSystem.Log("=============================================================收到消息" + protoCode);
                         ms.Read(protoContent, 0, protoContent.Length);
                         if (isCompress)
                         {
                             protoContent = GZipCompress.DeCompress(protoContent);
                         }
                         if (protoCode == OP_PLAYER_CLOSE.CODE)
                         {
                             LogSystem.LogSpecial("服务器返回关闭消息,网络连接断开");
                             Close(true);
                         }
                         else if (protoCode == OP_SYS_HEART.CODE)
                         {
                             lastHeart = OP_SYS_HEART.decode(protoContent);
                         }
                         else
                         {
                             //return;
                             NetDispatcher.Instance.Dispatch(protoCode, protoContent);
                         }
                     }
                 }
                 else
                 {
                     break;
                 }
             }
         }
         else
         {
             m_ReceiveCount = 0;
             break;
         }
     }
     m_SocketStateDic[m_CurrentState].OnUpdate();
 }
Exemplo n.º 27
0
 //玩家属性表条目中获取对应索引的属性信息
 public bool getPropTableItem(GlobalServerMsg id, ref Propetry type)
 {
     if (!m_propertyTable.ContainsKey(id))
     {
         LogSystem.Log("has not found prop index ", id);
         return(false);
     }
     type = m_propertyTable[id];
     return(true);
 }
Exemplo n.º 28
0
        /// <summary>
        /// 获取配表
        /// </summary>
        /// <param name="cfgName">配表文件名称</param>
        public AssetConfig GetConfig(string cfgName)
        {
            if (_cfgs.ContainsKey(cfgName))
            {
                return(_cfgs[cfgName]);
            }

            LogSystem.Log(ELogType.Error, $"Not found config {cfgName}");
            return(null);
        }
Exemplo n.º 29
0
        public void Execute()
        {
            LogSystem.Log("开始换牌,模式" + m_Mode.ToString());
            RoomMaJiangProxy.Instance.SwapPoker(m_Mode, m_PlayerPokers);

            if (MaJiangSceneCtrl.Instance != null)
            {
                MaJiangSceneCtrl.Instance.PlaySwapAnimation(m_Mode);
            }
        }
Exemplo n.º 30
0
    /// <summary>
    /// 返回登录界面
    /// </summary>
    public void GoBackLogin()
    {
        LogSystem.Log("Game::GoBackLogin");
        UnInitNetWork();

        //初始化网络
        InitNetWork();
        //初始化游戏世界
        InitGameWord();
    }