Exemple #1
0
        private void btnLuaRunPath_Click(object sender, EventArgs e)
        {
            try
            {
                string host     = txtHost.Text;
                int    port     = txtPort.Text.ToInt();
                int    actionId = txtAction.Text.ToInt();
                string pwd      = txtPwd.Text.Trim();
                _token.GameType = txtGameType.Text.ToInt();
                _token.ServerID = txtServerID.Text.ToInt();
                _token.RetailID = txtRetailID.Text.Trim();
                _token.Pid      = txtPid.Text.Trim();
                _token.Pwd      = EncodePwdAndUrlEncode(pwd);
                SetConfig(host, port, actionId, _token, pwd);

                string funName = string.Format("Action{0}", actionId);
                ScutWriter.getInstance().writeHead(_token.Sid, _token.Uid.ToInt());
                ScutWriter.getInstance().writeInt32("ActionId", actionId);
                if (!LuaRuntime.GetContext().TryCall <Action <UserToken> >(funName, _token))
                {
                    _responseLog.WriteFormatLine("请求出错:The {0} function is not exist in lua file.", funName);
                }
                var sendData = ScutWriter.generatePostData();
                TcpRequest.Instance().Send(host, port, sendData, null);
                ScutWriter.resetData();
            }
            catch (Exception ex)
            {
                _responseLog.WriteFormatLine("请求出错:{0}", ex);
            }
            finally
            {
                ResponseReflesh();
            }
        }
Exemple #2
0
        private void OnReceiveCompleted(SocketClient sender, byte[] data)
        {
            try
            {
                ScutReader.GetIntance().Reader = new MessageStructure(data);
                bool     result   = ScutReader.GetIntance().getResult();
                int      actionId = ScutReader.GetIntance().readAction();
                string   funName  = string.Format("_{0}Callback", actionId);
                LuaTable table;
                if (!LuaRuntime.GetContext().TryCall <Func <UserToken, LuaTable>, LuaTable>(funName, out table, _token))
                {
                    _responseLog.WriteFormatLine("接收出错:The {0} function is not exist in lua file.", funName);
                }
                else if (result)
                {
                    _responseLog.WriteTable("接收Action:" + actionId + "成功!Error:" + ScutReader.GetIntance().readErrorCode(), table);
                }
            }
            catch (Exception ex)
            {
                _responseLog.WriteFormatLine("接收出错:{0}", ex);
            }
            finally
            {
#if DEBUG
#else
                ResponseReflesh();
#endif
            }
        }
Exemple #3
0
        public Main()
        {
            InitializeComponent();
            rtxtResponse.ReadOnly = true;
            LuaRuntime.GetContext().RegisterFunc("LogWriteLine", _responseLog, _responseLog.GetType().GetMethod("WriteLine"));
            LuaRuntime.GetContext().RegisterFunc("LogWriteTable", _responseLog, _responseLog.GetType().GetMethod("WriteTable"));
            InitConfig();
            TcpRequest.Instance().ReceiveCompleted += OnReceiveCompleted;

            _watchThread = new Thread(obj =>
            {
                var instance = obj as Main;
                while (true)
                {
                    Thread.Sleep(100);
                }
            });
        }