Exemplo n.º 1
0
        protected override void SuccessCallback(MessageStructure writer, MessageHead head)
        {
            int type = writer.ReadInt();

            if (type == 1)
            {
                int               recordCount   = writer.ReadInt();
                JsonObject        jsonContainer = new JsonObject();
                List <JsonObject> jsonList      = new List <JsonObject>();
                for (int i = 0; i < recordCount; i++)
                {
                    writer.RecordStart();
                    var item = new JsonObject();
                    item.Add("NoticeID", writer.ReadString());
                    item.Add("Title", writer.ReadString());
                    item.Add("Content", writer.ReadString());
                    item.Add("IsBroadcast", writer.ReadInt());
                    item.Add("IsTop", writer.ReadInt());
                    item.Add("Creater", writer.ReadString());
                    item.Add("CreateDate", writer.ReadString());
                    item.Add("ExpiryDate", writer.ReadString());
                    jsonList.Add(item);
                    writer.RecordEnd();
                }
                jsonContainer.Add("total", recordCount);
                jsonContainer.Add("rows", jsonList.ToArray());
                WriteTableJson(jsonContainer);
            }
        }
Exemplo n.º 2
0
        protected override bool DecodePacket(MessageStructure reader, MessageHead head)
        {
            _session.Context.SessionId = reader.ReadString();
            _session.Context.UserId    = reader.ReadString().ToInt();
            int    UserType  = reader.ReadInt();
            string LoginTime = reader.ReadString();
            int    GuideID   = reader.ReadInt();

            if (GuideID == 1005)
            {
                SetChildStep("1005");
            }
            return(true);
        }
Exemplo n.º 3
0
        public static void LoadServerConfig()
        {
            try
            {
                string         url        = ConfigurationManager.AppSettings["ServerSerUrl"];
                HttpStatusCode statusCode = (HttpStatusCode)0;
                byte[]         data       = HttpPostManager.GetPostData(url, null, out statusCode);

                if (data != null && data.Length > 0)
                {
                    MessageStructure ms = new MessageStructure(data);
                    int    length       = ms.ReadInt();
                    int    errcode      = ms.ReadInt();
                    int    msgid        = ms.ReadInt();
                    string errorInfo    = ms.ReadString();
                    int    actionId     = ms.ReadInt();
                    string st           = ms.ReadString();
                    int    lastloginid  = ms.ReadInt();
                    int    listsize     = ms.ReadInt();
                    for (int i = 0; i < listsize; ++i)
                    {
                        ServerInfo info = new ServerInfo();
                        info.ID           = ms.ReadInt();
                        info.ServerName   = ms.ReadString();
                        info.Status       = ms.ReadString();
                        info.StatusCode   = ms.ReadInt();
                        info.ServerUrl    = ms.ReadString();
                        info.Weight       = ms.ReadInt();
                        info.TargetServer = ms.ReadInt();
                        Set.Add(info);
                    }

                    TraceLog.WriteLine("Request server list successful!");
                }
                else
                {
                    TraceLog.ReleaseWrite("Request server list fail result:{0}, request url:{1}", data, url);
                    return;
                }
            }
            catch (Exception ex)
            {
                new BaseLog().SaveLog(ex);
                return;
            }
        }
Exemplo n.º 4
0
        protected override bool DecodePacket(MessageStructure reader, MessageHead head)
        {
            int    msgLenth = reader.ReadInt();
            string msgBody  = reader.ReadString();

            _session.Context.SessionId = msgBody;

            return(true);
        }
        public static void LoadServerRanking()
        {
            try
            {
                var          ranking      = RankingFactory.Get <UserRank>(LevelRanking.RankingKey);
                LevelRanking levelranking = ranking as LevelRanking;
                levelranking.rankingData.RankTime = DateTime.Now;
                levelranking.rankingData.RankList.Clear();


                foreach (var v in ServerSet.Set)
                {
                    string   url   = v.ServerUrl;
                    string[] split = url.Split(':');
                    url = "http://" + split[0] + ":8091/GlobalCommon.aspx?";
                    url = url + HttpUtility.UrlEncode("ID=LevelRankingData");

                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                    request.Timeout = 5000;
                    request.Method  = "GET";
                    WebResponse     webresponse  = request.GetResponse();
                    HttpWebResponse httpResponse = (HttpWebResponse)webresponse;
                    Stream          stream       = httpResponse.GetResponseStream(); //获取响应的字符串流  
                    StreamReader    sr           = new StreamReader(stream);         //创建一个stream读取流  
                    string          data         = sr.ReadToEnd();                   //从头读到尾,放到字符串html  

                    if (data != null && data.Length > 0)
                    {
                        byte[]           bytes = Convert.FromBase64String(data);
                        MessageStructure ms    = new MessageStructure(bytes);

                        int listsize = ms.ReadInt();
                        for (int i = 0; i < listsize; ++i)
                        {
                            UserRank rank = new UserRank();
                            rank.UserID     = ms.ReadInt();
                            rank.NickName   = ms.ReadString();
                            rank.Profession = ms.ReadInt();
                            rank.RankId     = ms.ReadInt();
                            rank.UserLv     = ms.ReadInt();
                            rank.AvatarUrl  = ms.ReadString();
                            rank.FightValue = ms.ReadInt();
                            rank.VipLv      = ms.ReadInt();
                            levelranking.rankingData.RankList.Add(rank);
                        }
                    }
                }


                Ranking <UserRank> levelRanking = RankingFactory.Get <UserRank>(LevelRanking.RankingKey);
                levelRanking.ForceRefresh();
            }
            catch (Exception ex)
            {
                new BaseLog().SaveLog(ex);
                return;
            }
        }
Exemplo n.º 6
0
        public MessageHead GetReadHeader(MessageStructure reader)
        {
            MessageHead rtnHeader = new MessageHead();

            int msgType = reader.ReadInt();

            if (msgType == 0)
            {
                return(rtnHeader);
            }

            rtnHeader = new MessageHead(msgType, 0, "");

            return(rtnHeader);
        }
Exemplo n.º 7
0
        public static int Action1000(int userId)
        {
            var result = 0;
            var param  = new RequestParam();

            param.Add("UserId", userId);
            AutoResetEvent waitHandle = new AutoResetEvent(false);

            tcpRemote.Call("Battle1000", param, package =>
            {
                var reader = new MessageStructure(package.Message as byte[]);
                result     = reader.ReadInt();
                waitHandle.Set();
            });
            waitHandle.WaitOne(5000);
            return(result);
        }
Exemplo n.º 8
0
        public static bool GetFieldValue(MessageStructure ms, FieldType fieldType, ref string val)
        {
            bool result = false;

            switch (fieldType)
            {
            case FieldType.Int:
                val    = ms.ReadInt().ToString();
                result = true;
                break;

            case FieldType.Password:
            case FieldType.String:
                val    = ms.ReadString();
                result = true;
                break;

            case FieldType.Short:
                val    = ms.ReadShort().ToString();
                result = true;
                break;

            case FieldType.Byte:
                val    = ms.ReadByte().ToString();
                result = true;
                break;

            case FieldType.Long:
                val    = ms.ReadLong().ToString();
                result = true;
                break;

            case FieldType.Bool:
                val    = ms.ReadBool().ToString();
                result = true;
                break;

            case FieldType.Float:
                val    = ms.ReadFloat().ToString();
                result = true;
                break;

            case FieldType.Double:
                val    = ms.ReadDouble().ToString();
                result = true;
                break;

            case FieldType.DateTime:
                val    = ms.ReadDateTime().ToString();
                result = true;
                break;

            case FieldType.ULong:
                val    = ms.ReadUInt64().ToString();
                result = true;
                break;

            case FieldType.UInt:
                val    = ms.ReadUInt32().ToString();
                result = true;
                break;

            case FieldType.UShort:
                val    = ms.ReadUInt16().ToString();
                result = true;
                break;

            case FieldType.Record:
                break;

            case FieldType.End:
                break;

            case FieldType.Void:
                break;

            default:
                break;
            }

            return(result);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 处理循环记录
        /// </summary>
        /// <param name="respContent"></param>
        /// <param name="queue"></param>
        /// <param name="reader"></param>
        private static void ProcessLoopRocord(StringBuilder respContent, List <ParamInfoModel> queue, MessageStructure reader)
        {
            StringBuilder headContent    = new StringBuilder();
            StringBuilder builderContent = new StringBuilder();
            int           recordCount    = 0;

            try
            {
                recordCount = reader.ReadInt();
            }
            catch (Exception ex)
            {
            }
            respContent.Append("<tr>");
            respContent.Append("<td style=\"width:25%;\" align=\"left\">Record(N)</td>");
            respContent.Append("<td style=\"width:20%;\" align=\"left\">Record</td>");
            respContent.AppendFormat("<td style=\"width:50%;\" align=\"left\">{0}</td>", recordCount);
            respContent.Append("</tr>");

            respContent.Append("<tr><td colspan=\"3\" align=\"center\">");
            respContent.Append("<!--子表开始--><table style=\"width:98%; border-color:#f0f0f0\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">");
            if (recordCount == 0)
            {
                builderContent.Append("<tr><td align=\"center\">空数据</td></tr>");
            }


            for (int i = 0; i < recordCount; i++)
            {
                try
                {
                    reader.RecordStart();
                    MessageStructure msgReader = reader;
                    int loopDepth = 0; //循环深度
                    List <ParamInfoModel> recordQueue = new List <ParamInfoModel>();

                    headContent.Append("<tr><!--头开始tr-->");
                    builderContent.Append("<tr><!--内容开始tr-->");
                    int columnNum = 0;

                    #region

                    for (int r = 1; r < queue.Count - 1; r++)
                    {
                        var       record     = queue[r];
                        string    fieldName  = record.Field;
                        FieldType fieldType  = record.FieldType;
                        string    fieldValue = "";
                        try
                        {
                            if (loopDepth > 0 && fieldType == FieldType.End)
                            {
                                loopDepth--;
                                recordQueue.Add(record);
                            }
                            if (loopDepth == 0 && recordQueue.Count > 0)
                            {
                                builderContent.Append("</tr><tr>");
                                builderContent.AppendFormat("<td colspan=\"{0}\" align=\"right\">", columnNum);
                                builderContent.Append(
                                    "<!--子表开始--><table style=\"width:95%; border-color:#f0f0f0\" border=\"1\" cellpadding=\"2\" cellspacing=\"0\">");
                                //处理循环记录
                                ProcessLoopRocord(builderContent, recordQueue, msgReader);

                                builderContent.Append("</table><!--子表结束-->");
                                builderContent.Append("</td>");
                                recordQueue.Clear();
                            }

                            if (loopDepth == 0)
                            {
                                if (NetHelper.GetFieldValue(msgReader, fieldType, ref fieldValue))
                                {
                                    if (i == 0)
                                    {
                                        headContent.AppendFormat("<td align=\"center\"><strong>{0}</strong>({1})</td>",
                                                                 fieldName, fieldType);
                                    }
                                    builderContent.AppendFormat("<td align=\"center\">&nbsp;{0}</td>", (fieldValue ?? "").Replace("{", "%7B").Replace("}", "%7D"));
                                    columnNum++;
                                }
                                if (fieldType == FieldType.Record)
                                {
                                    loopDepth++;
                                    recordQueue.Add(record);
                                }
                            }
                            else if (fieldType != FieldType.End)
                            {
                                if (fieldType == FieldType.Record)
                                {
                                    loopDepth++;
                                }
                                recordQueue.Add(record);
                            }
                        }
                        catch (Exception ex)
                        {
                            builderContent.AppendFormat("<td align=\"center\">{0}列出错{1}</td>", fieldName, ex.Message);
                        }
                    }

                    #endregion

                    headContent.Append("</tr><!--头结束tr-->");
                    builderContent.Append("</tr><!--内容结束tr-->");
                    //读取行结束
                    reader.RecordEnd();
                }
                catch (Exception ex)
                {
                    builderContent.AppendFormat("<tr><td align=\"left\">{0}行出错{1}</td></tr>", (i + 1), ex.Message);
                    break; //读流出错,直接退出
                }
            }

            respContent.Append(headContent.ToString());
            respContent.Append(builderContent.ToString());
            respContent.Append("</table><!--子表结束-->");
            respContent.Append("</td></tr>");
            respContent.Append("<tr>");
            respContent.Append("<td colspan=\"3\" align=\"left\">End</td>");
            respContent.Append("</tr>");
        }
Exemplo n.º 10
0
        private static void ParseRecordEnd(StringBuilder itemBuilder, MessageStructure reader, List <DataRow> queue, int depth, int recordNum, string[] keyNames)
        {
            MessageStructure msgReader   = reader;
            string           keyValue    = string.Empty;
            string           keyName     = keyNames.Length > depth ? keyNames[depth] : string.Empty;
            List <LuaConfig> builderList = new List <LuaConfig>();
            int recordCount = 0;

            try
            {
                recordCount = msgReader.ReadInt();
            }
            catch { }
            for (int i = 0; i < recordCount; i++)
            {
                try
                {
                    msgReader.RecordStart();
                    int            loopDepth     = 0; //ѭ�����
                    StringBuilder  recordBuilder = new StringBuilder();
                    List <DataRow> recordQueue   = new List <DataRow>();

                    int columnNum = 0;
                    int childNum  = 0;

                    #region ������ȡ����
                    for (int r = 1; r < queue.Count - 1; r++)
                    {
                        DataRow   record     = queue[r];
                        string    fieldName  = record["Field"].ToString();
                        FieldType fieldType  = (FieldType)Enum.Parse(typeof(FieldType), record["FieldType"].ToString());
                        string    fieldValue = "";
                        try
                        {
                            if (loopDepth > 0 && fieldType == FieldType.End)
                            {
                                loopDepth--;
                                recordQueue.Add(record);
                            }
                            if (loopDepth == 0 && recordQueue.Count > 0)
                            {
                                //����ѭ����¼
                                childNum++;
                                var childBuilder = new StringBuilder();
                                ParseRecordEnd(childBuilder, msgReader, recordQueue, depth + 1, childNum, keyNames);
                                //
                                recordQueue.Clear();
                                //ѡ�������ʽ
                                FormatChildToLua(recordBuilder, childBuilder, columnNum);
                            }

                            if (loopDepth == 0)
                            {
                                if (NetHelper.GetFieldValue(msgReader, fieldType, ref fieldValue))
                                {
                                    if (columnNum > 0)
                                    {
                                        recordBuilder.Append(",");
                                    }
                                    if (fieldName.Trim().ToLower() == keyName.Trim().ToLower())
                                    {
                                        keyValue = fieldValue;
                                    }
                                    if (fieldType == FieldType.Byte || fieldType == FieldType.Short || fieldType == FieldType.Int)
                                    {
                                        recordBuilder.AppendFormat("{0}={1}", fieldName, fieldValue);
                                    }
                                    else
                                    {
                                        recordBuilder.AppendFormat("{0}=\"{1}\"", fieldName, fieldValue);
                                    }
                                    columnNum++;
                                }
                                if (fieldType == FieldType.Record)
                                {
                                    loopDepth++;
                                    recordQueue.Add(record);
                                }
                            }
                            else if (fieldType != FieldType.End)
                            {
                                if (fieldType == FieldType.Record)
                                {
                                    loopDepth++;
                                }
                                recordQueue.Add(record);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception(string.Format("recordindex:{0},fieldName:{1} error:", i, fieldName), ex);
                        }
                    }

                    #endregion
                    //��ȡ�н���
                    msgReader.RecordEnd();
                    builderList.Add(new LuaConfig {
                        Key = keyValue, Builder = recordBuilder
                    });
                }
                catch (Exception ex)
                {
                    throw new Exception(string.Format("recordindex:{0}error:", i), ex);
                }
            }

            FormatListToLua(itemBuilder, builderList, keyName, depth, recordNum);
        }
Exemplo n.º 11
0
 protected override bool DecodePacket(MessageStructure reader, MessageHead head)
 {
     _session.Context.UserId = reader.ReadInt();
     return(true);
 }