Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="session"></param>
 override public void sessionCreated(object session)
 {
     try
     {
         //request ƾ֤
         RCLogic.netNeedProof((AppSession)session);
     }
     catch (Exception exd)
     {
         Log.WriteStrByException("RecordSocketDataHandler", "sessionCreated", exd.Message);
     }
 }
Пример #2
0
        public void msgTimedEvent(object source, ElapsedEventArgs e)
        {
            SmqOppResult ruCount = msgList.Opp(QueueMethod.Count, null);

            int len = ruCount.count;

            for (int i = 0; i < len; i++)
            {
                SmqOppResult ruShift = msgList.Opp(QueueMethod.Shift, null);

                if (!ruShift.oppSucess)
                {
                    continue;
                }

                SessionMessage item = ruShift.item;

                //
                XmlDocument doc       = item.doc();
                string      strIpPort = item.strIpPort();
                string      action    = item.action();
                AppSession  c         = null;

                c = item.e();

                //
                item.Dereference();

                //
                if (RCClientAction.loadG == action)
                {
                    RCLogic.doorLoadG(c, doc);

                    continue;
                }

                if (RCClientAction.betG == action)
                {
                    RCLogic.doorBetG(c, doc);

                    continue;
                }

                if (RCClientAction.updG == action)
                {
                    RCLogic.doorUpdG(c, doc);

                    continue;
                }

                if (RCClientAction.updHonor == action)
                {
                    RCLogic.doorUpdHonor(c, doc);

                    continue;
                }

                if (RCClientAction.login == action)
                {
                    RCLogic.doorLogin(c, doc);

                    continue;
                }

                if (RCClientAction.hasReg == action)
                {
                    RCLogic.doorHasReg(c, doc);

                    continue;
                }

                if (RCClientAction.reg == action)
                {
                    RCLogic.doorReg(c, doc);

                    continue;
                }

                if (RCClientAction.chkEveryDayLoginAndGet == action)
                {
                    RCLogic.doorChkEveryDayLoginAndGet(c, doc);

                    continue;
                }

                if (RCClientAction.loadChart == action)
                {
                    RCLogic.doorLoadChart(c, doc);

                    continue;
                }

                if (RCClientAction.loadTopList == action)
                {
                    RCLogic.doorLoadTopList(c, doc);

                    continue;
                }

                if (RCClientAction.hasProof == action)
                {
                    RCLogic.doorHasProof(c, doc);

                    continue;
                }

                if (RCClientAction.loadDBType == action)
                {
                    RCLogic.doorLoadDBType(c, doc);

                    continue;
                }

                //Log.WriteStr("无效协议号:" + clientServerAction);
                Log.WriteStr(SR.GetString(SR.Invalid_protocol_num, action));
            }   //end for
        }
Пример #3
0
        static void Main(string[] args)
        {
            try
            {
                //设置控制台的显示样式
                Console.ForegroundColor = ConsoleColor.Green;

                //显示在控制台上
                //copy right
                Console.WriteLine("wdmir.com   2003-2015");
                Console.WriteLine("www.silverFoxServer.net 2009-2015");


                //语言
                //mono不支持Culture
                //"zh-CN";
                String lang = System.Globalization.CultureInfo.InstalledUICulture.Name;

                SR.init(lang);

                //
                Console.Title = SR.GetString(SR.Win_Title, SR.Record_displayName, "3.0", "2015/8/28");

                //最近在项目中用到的,实在没有兴趣去写成Windows Service方式,只能最简单的Console方式了!
                //再在特定条件下启动后能够后台执行或者最小化到任务栏而不会挡在屏幕中央!基本思路是P/Invoke方式:
                //http://www.cnblogs.com/pccai/archive/2011/03/08/1977692.html
                if (args.Length > 0 && args[0] == "nowin")
                {
                    IntPtr ParenthWnd = new IntPtr(0);
                    IntPtr et         = new IntPtr(0);
                    ParenthWnd = FindWindow(null, Console.Title);

                    ShowWindow(ParenthWnd, 0);//隐藏本dos窗体, 0: 后台执行;1:正常启动;2:最小化到任务栏;3:最大化
                }

                //
                GameGlobals.GAME_NAME = SERVER_NAME;

                //打印级别
                GameGlobals.logLvl = LoggerLvl.ALL2;
                Log.init(GameGlobals.GAME_NAME, GameGlobals.logLvl);

                //
                string configFile = "RecordServerConfig.xml";


                //读取xml配置
                XmlDocument configDoc = new XmlDocument();

                //Console.WriteLine("[Load File] " + configFile);
                Console.WriteLine(SR.GetString(SR.LoadFile, configFile));


                configDoc.Load(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + configFile);
                //configDoc.Load(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "server_config_" + gameName + ".xml");

                //
                XmlNode rcNodeFile = configDoc.SelectSingleNode("/www.wdmir.net/group/database-file");

                if (null == rcNodeFile)
                {
                    Console.WriteLine("can not find node: /www.wdmir.net/group/database-file");
                }

                //
                string localPath  = rcNodeFile.ChildNodes[0].InnerText;
                bool   localUsing = Convert.ToBoolean(Convert.ToInt32(rcNodeFile.ChildNodes[0].Attributes["using"].Value));

                //dz可自定字段
                string dzPath  = rcNodeFile.ChildNodes[1].InnerText;
                bool   dzUsing = Convert.ToBoolean(Convert.ToInt32(rcNodeFile.ChildNodes[1].Attributes["using"].Value));
                string dzVer   = rcNodeFile.ChildNodes[2].InnerText;
                string dzSql   = rcNodeFile.ChildNodes[3].InnerText;

                String dzSqlEngine = rcNodeFile.ChildNodes[3].Attributes["engine"].Value;

                string dzTablePre = rcNodeFile.ChildNodes[4].InnerText;
                string dzCloumn   = rcNodeFile.ChildNodes[5].InnerText;

                //缺省字段
                string pwPath     = rcNodeFile.ChildNodes[6].InnerText;
                bool   pwUsing    = Convert.ToBoolean(Convert.ToInt32(rcNodeFile.ChildNodes[6].Attributes["using"].Value));
                string pwVer      = rcNodeFile.ChildNodes[7].InnerText;
                string pwSql      = rcNodeFile.ChildNodes[8].InnerText;
                string pwTablePre = rcNodeFile.ChildNodes[9].InnerText;
                string pwCloumn   = rcNodeFile.ChildNodes[10].InnerText;

                //phpbb
                string phpbbPath     = rcNodeFile.ChildNodes[11].InnerText;
                bool   phpbbUsing    = Convert.ToBoolean(Convert.ToInt32(rcNodeFile.ChildNodes[11].Attributes["using"].Value));
                string phpbbVer      = rcNodeFile.ChildNodes[12].InnerText;
                string phpbbSql      = rcNodeFile.ChildNodes[13].InnerText;
                string phpbbTablePre = rcNodeFile.ChildNodes[14].InnerText;
                string phpbbCloumn   = rcNodeFile.ChildNodes[15].InnerText;

                //缺省字段
                string xPath        = rcNodeFile.ChildNodes[16].InnerText;
                bool   xUsing       = Convert.ToBoolean(Convert.ToInt32(rcNodeFile.ChildNodes[16].Attributes["using"].Value));
                string xVer         = rcNodeFile.ChildNodes[17].InnerText;
                string xSql         = rcNodeFile.ChildNodes[18].InnerText;
                string xTable       = rcNodeFile.ChildNodes[19].InnerText;
                string xCloumnId    = rcNodeFile.ChildNodes[20].InnerText;
                string xCloumnNick  = rcNodeFile.ChildNodes[21].InnerText;
                string xCloumnMail  = rcNodeFile.ChildNodes[22].InnerText;
                string xTableMoney  = rcNodeFile.ChildNodes[23].InnerText;
                string xCloumnMoney = rcNodeFile.ChildNodes[24].InnerText;

                String xTableSession    = rcNodeFile.ChildNodes[25].InnerText;
                String xCloumnSessionId = rcNodeFile.ChildNodes[26].InnerText;

                //多数据库选择
                //if (localUsing)
                //{
                //    Console.WriteLine(SR.Local_Xml_DB + " " + localPath);

                //}
                //else
                if (dzUsing)
                {
                    RCLogic.selectDB = new DBTypeModel(DBTypeModel.DZ, dzPath, dzVer, dzSql);

                    //Console.WriteLine("Discuz数据库, 版本:" + dzVer + " 类型:" + dzSql);
                    Console.WriteLine(SR.GetString(SR.DB_Desc, "Discuz", dzVer, dzSql));
                }
                else if (pwUsing)
                {
                    //Console.WriteLine("Phpwind数据库, 版本:" + pwVer + " 类型:" + pwSql);
                    Console.WriteLine(SR.GetString(SR.DB_Desc, "Phpwind", pwVer, pwSql));
                }
                else if (xUsing)
                {
                    //Console.WriteLine("自定义数据库, 版本:" + xVer + " 类型:" + xSql);
                    Console.WriteLine(SR.GetString(SR.DB_Desc, SR.Custom, xVer, xSql));
                }
                else
                {
                    //Console.WriteLine("未定义数据库类型");
                    Console.WriteLine(SR.NoDefine_DB_Type);
                }

                //
                XmlNode ipNode = configDoc.SelectSingleNode("/www.wdmir.net/group/record-server");

                if (null == ipNode)
                {
                    //Console.WriteLine("/www.wdmir.net/group/record-server节点无法找到");
                    Console.WriteLine("can not find node: /www.wdmir.net/group/record-server");
                }



                string ipAdr = ipNode.ChildNodes[0].InnerText;

                int port = int.Parse(ipNode.ChildNodes[1].InnerText);

                string proof = ipNode.ChildNodes[2].InnerText;

                string tableLog          = ipNode.ChildNodes[3].InnerText;
                bool   autoClearTableLog = Convert.ToBoolean(
                    Convert.ToInt32(ipNode.ChildNodes[3].Attributes["autoClearWithStart"].Value)
                    );

                string tableEveryDayLogin          = ipNode.ChildNodes[4].InnerText;
                bool   autoClearTableEveryDayLogin = Convert.ToBoolean(
                    Convert.ToInt32(ipNode.ChildNodes[4].Attributes["autoClearWithStart"].Value)
                    );



                string tableHonor = ipNode.ChildNodes[5].InnerText;
                String TableUsers = ipNode.ChildNodes[6].InnerText;

                if ("" == tableLog)
                {
                    tableLog = "game_logs";
                }

                //Console.WriteLine("[Load File] OK");

                Console.WriteLine(SR.LoadFileSuccess);
                //Console.WriteLine("配置文件解析成功!");

                if (!RCLogic.Init(localPath,
                                  dzPath, dzVer, dzSql, dzSqlEngine, dzTablePre, dzCloumn,
                                  pwPath, pwVer, pwSql, pwTablePre, pwCloumn,
                                  phpbbPath, phpbbVer, phpbbSql, phpbbTablePre, phpbbCloumn,
                                  xPath, xVer, xSql, xTable, xCloumnId, xCloumnNick, xCloumnMail, xTableMoney, xCloumnMoney,
                                  xTableSession, xCloumnSessionId,
                                  proof,
                                  tableLog, autoClearTableLog,
                                  tableEveryDayLogin, autoClearTableEveryDayLogin,
                                  tableHonor, TableUsers))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    //Console.WriteLine("数据库文件初始化失败");
                    Console.WriteLine(SR.DB_File_Init_Failed);

                    Console.ForegroundColor = ConsoleColor.Green;

                    Console.ReadLine();
                    return;
                }

                //
                RCLogicLPU.getInstance().init();

                //启动侦听
                SocketAcceptorSync acceptor = new SocketAcceptorSync();

                acceptor.setHandler(new RecordSocketDataHandler());

                //acceptor.getSessionConfig().setReadBufferSize(1024 * 4);

                acceptor.bind(ipAdr, port, true);

                //对于post builder,这里要加ReadLine
                string line;
                while ((line = Console.ReadLine()) != SR.Shutdown)
                {
                    if (null == line)
                    {
                        //break;
                    }
                    else if (line == "shutdown")
                    {
                        break;
                    }
                    else if (line == "clear")
                    {
                        Console.Clear();
                    }
                    else
                    {
                        Console.WriteLine("unknow command");
                    }
                    //Console.WriteLine("run command:" + line);
                }

                //Console.ReadLine();
            }
            catch (Exception exd)
            {
                Console.ForegroundColor = ConsoleColor.Red;

                Console.WriteLine(SR.GetString(SR.Record_svr_start_failed, exd.Message));
                Console.ForegroundColor = ConsoleColor.Green;

                Console.WriteLine(SR.GetString(SR.Game_svr_failed_help));

                Console.WriteLine("email:[email protected]");

                Console.ReadLine();
            }
        }