Beispiel #1
0
        void HandleServerList(IPacketMsg packetMsg)
        {
            var listMsg = new ClientMsgProtobuf <CMsgClientServerList>(packetMsg);

            foreach (var server in listMsg.Body.servers)
            {
                EServerType type = ( EServerType )server.server_type;

                List <IPEndPoint> endpointList;
                if (!serverMap.TryGetValue(type, out endpointList))
                {
                    serverMap[type] = endpointList = new List <IPEndPoint>();
                }

                endpointList.Add(new IPEndPoint(NetHelpers.GetIPAddress(server.server_ip), ( int )server.server_port));
            }
        }
Beispiel #2
0
        /// <summary>
        ///    Initializes a new instance of the <see cref="Packet" /> class.
        /// </summary>
        public Packet(EServerType server_type, EPacketType type, byte cmd)
        {
            BufferChunk.SetNetworking();
            Header = new PacketHeader(server_type);

            Header.type          = (byte)type;
            Header.value         = cmd;
            Header.packet_number = PacketNumber++;
            Header.datalength    = 1;
            var len = PacketHeader.Length;

            len += Header.datalength;
            Data = new BufferChunk((int)len);
            Data.Add(Header);

            AddChecksumm();
        }
        public static void RunServer(Assembly assembly, EServerType serverType, ConfigInfo allConfig)
        {
            string serverTypeStr = "Lockstep.Server." + serverType.ToString().Replace("Server", "") + "." +
                                   (serverType).ToString();
            var type = assembly.GetType(serverTypeStr);

            if (type == null)
            {
                Console.WriteLine("StartServerFailed!: have no server type:" + serverTypeStr);
                return;
            }

            var        sobj   = Activator.CreateInstance(type);
            BaseServer server = sobj as BaseServer;

            server.serverType = serverType;
            RunServer(assembly, server, allConfig);
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            EServerType serverType = EServerType.DaemonServer;

            if (args.Length > 0)
            {
                if (Enum.TryParse <EServerType>(args[0], out var type))
                {
                    serverType = type;
                }
                else
                {
                    Console.WriteLine("StartServer failed! Unknown server type " + args[0]);
                    return;
                }
            }
            ServerUtil.RunServerInThread(typeof(Program).Assembly, serverType);
        }
Beispiel #5
0
Datei: TMPlan.cs Projekt: x2v0/TM
        /// <summary>
        ///    Sends the EPlanCommand to server.
        ///    <code>
        /// public enum EPlanCommand
        /// {
        ///    [Description("запрос на статус сервера")]
        ///    GETSTATE = 1,
        ///
        ///    [Description("запрос на очистку плана ")]
        ///    CLEARPLAN = 2,
        ///
        ///    [Description("запрос на старт плана ")]
        ///    STARTPLAN = 3,
        ///
        ///    [Description("запрос на паузу")]
        ///    PAUSEPLAN = 4,
        ///
        ///    [Description("запрос на останов")]
        ///    STOPPLAN = 5
        /// }
        /// </code>
        /// </summary>
        /// <param name="cmd">The EPlanCommand.</param>
        /// <param name="server_type">Type of the server.</param>
        /// <returns><c>true</c> on success, <c>false</c> otherwise.</returns>
        /// <exception cref="TM.SendCommandException"></exception>
        public virtual bool SendCommand(EPlanCommand cmd, EServerType server_type = EServerType.MCS)
        {
            if (!IsConnected)
            {
                if (Globals.Debug)
                {
                    Console.WriteLine(Resources.Server_is_not_connected);
                }
                return(false);
            }

            bool ret;

            if (cmd == EPlanCommand.CLEARPLAN)
            {
                ClearPlan();
            }

            try {
                var packet = new Packet(server_type, EPacketType.Command, (byte)cmd);
                if (Globals.Debug)
                {
                    Console.WriteLine(Resources.Sending_command_to_server + ": " + cmd.Description());
                }

                ret = Send(packet);
            } catch (Exception ex) {
                var msg = "SendCommand : " + cmd + " - " + ex.Message;

                if (Globals.Debug)
                {
                    Console.WriteLine(msg);
                }

                throw new SendCommandException(msg);
            }

            if (Globals.Debug && !ret)
            {
                Console.WriteLine(Resources.Network_error);
            }
            return(ret);
        }
Beispiel #6
0
        public ConnectDescriptorData(IConnectDescriptor data)
        {
            host = data.Host;
            port = data.Port;

            if (usingSid = data.UsingSid)
            {
                sid          = data.Sid;
                serviceName  = string.Empty;
                instanceName = string.Empty;
            }
            else
            {
                serviceName  = data.ServiceName;
                instanceName = data.InstanceName;
                sid          = string.Empty;
            }

            serverType = data.ServerType;
        }
Beispiel #7
0
        /// <summary>
        ///    Initializes a new instance of the <see cref="Packet" /> class.
        /// </summary>
        public Packet(EServerType server_type, EPacketType type,
                      byte cmd, byte value = 0, byte[] data = null)
        {
            BufferChunk.SetNetworking();
            Header = new PacketHeader(server_type);

            Header.type          = (byte)type;
            Header.value         = value;
            Header.packet_number = PacketNumber++;
            var len = PacketHeader.Length + 1; // +1 checksum

            Header.datalength = 1;

            if ((data != null) &&
                (data.Length > 0))
            {
                Header.datalength += (uint)data.Length;
                len += Header.datalength;
                Data = new BufferChunk((int)len);
                Data.Add(Header);
                Data += data;
            }
            else
            {
                Data = new BufferChunk((int)len);
                Data.Add(Header);
            }

            AddChecksumm();

#if LOCAL_DEBUG
            Console.WriteLine(Encoding.ASCII.GetString(Header.sign));

            if (data != null)
            {
                var str = Encoding.ASCII.GetString(data);
                Console.WriteLine(str);
            }
#endif
        }
Beispiel #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Packet"/> class.
        /// </summary>
        public Packet(EServerType server_type, EPacketType type, string data)
        {
            BufferChunk.SetNetworking();
            Header = new PacketHeader(server_type);

            Header.type          = (byte)type;
            Header.value         = 0;
            Header.packet_number = PacketNumber++;
            data += "\0"; // quick&dirty

            if (!string.IsNullOrEmpty(data))
            {
                Header.datalength = (uint)data.Length + 1; // +1 checksum
                var len = PacketHeader.Length;
                len += Header.datalength;
                Data = new BufferChunk((int)len);
                Data.Add(Header);
                Data += data;
                var str = Encoding.ASCII.GetString(Data.Buffer);
            }
            else
            {
                Header.datalength = 1;
                Data = new BufferChunk((int)(PacketHeader.Length + 1));
                Data.Add(Header);
            }

            AddChecksumm();

#if LOCAL_DEBUG
            Console.WriteLine(Encoding.ASCII.GetString(Header.sign));

            if (!string.IsNullOrEmpty(data))
            {
                var str = data;
                Console.WriteLine(str);
            }
#endif
        }
        public void ServerStartUp(Int32 iPort, EServerType eType)
        {
            i_port = iPort;

            eServerType = eType;

            IPAddress lisenIP = IPAddress.Any;

            m_Listener   = new TcpListener(lisenIP, iPort);
            m_ListenerV6 = new TcpListener(IPAddress.IPv6Any, iPort);

            m_ListenThread = new Thread(new ThreadStart(ListenForClients));
            m_ListenThread.Start();
            m_ListenThreadV6 = new Thread(new ThreadStart(ListenForClientsV6));
            m_ListenThreadV6.Start();

            var addresses = Dns.GetHostAddresses(Dns.GetHostName());

            foreach (var adr in addresses)
            {
                AOutput.Log("\t" + adr.ToString());
            }
        }
		public MsgClientServerUnavailable()
		{
			JobidSent = 0;
			EMsgSent = 0;
			EServerTypeUnavailable = 0;
		}
Beispiel #11
0
        public static void PubMain1(string[] args, EServerType 默认服务器类型)
        {
            #region 初始化日志系统

            {
                try
                {
                    Util.Show("初始化日志系统......");
                    var log4netXmlFs  = new FileStream("..//Conf_Log//log4net_tpl.config", FileMode.Open);
                    var log4netXmlSr  = new StreamReader(log4netXmlFs);
                    var log4netXmlStr = log4netXmlSr.ReadToEnd();
                    log4netXmlStr = log4netXmlStr.Replace("$$$$$", $"{BaseServerInfo.ServerZoneSimple}{BaseServerInfo.ServerID}");
                    log4netXmlSr.Close();
                    var log4netXmlDoc = new XmlDocument();
                    log4netXmlDoc.LoadXml(log4netXmlStr);
                    var log4netRootElement = log4netXmlDoc.DocumentElement;
                    log4net.Config.XmlConfigurator.Configure(log4netRootElement);
                }
                catch
                {
                    loger.Fatal("读取INI配置文件 失败");
                    Console.ReadKey();
                    return;
                }
            }

            //Console.WriteLine("________________________________________________________________________________");
            //Loger.Debug("调试信息");
            //Loger.Info("普通信息");
            //Loger.Warn("警告信息");
            //Loger.Error("错误信息");
            //Loger.Fatal("严重错误");
            //Console.WriteLine("________________________________________________________________________________\n");

            #endregion 初始化日志系统

            #region 读取INI配置文件
            Util.Show("读取INI配置文件 ......");
            if (IniConf.InitIniConf())
            {
                //loger.Info("读取INI配置文件 成功");
            }
            else
            {
                loger.Fatal("读取INI配置文件 失败");
                Console.ReadKey();
                return;
            }

            #endregion 读取游戏配置文件

            #region 读取游戏配置文件

            Util.Show("读取游戏配置文件......");
            if (InitConf())
            {
                //loger.Info("初始化配置文件成功");
            }
            else
            {
                loger.Fatal("初始化配置文件失败");
                Console.ReadKey();
                return;
            }

            #endregion 读取游戏配置文件

            #region 设置窗口属性
            Console.SetWindowSize(160, 30);
            Console.SetBufferSize(160, 9600);
            #endregion 设置窗口属性

            #region 根据命令行参数重新配置服务器
            // XXX.exe [mode] [ServerID] [ServerIP] [ServerExtern]
            if (args.Length >= 4)
            {
                try
                {
                    BaseServerInfo.ServerRunMode = (EAccess)args[0].ToInt();
                    BaseServerInfo.ServerID      = args[1].ToInt();
                    BaseServerInfo.ServerIP      = args[2];
                    BaseServerInfo.ServerExtern  = args[3];
                    Console.Title = BaseServerInfo.ServerExtern;
                    Util.Show("使用程序 命令行参数 配置服务器");
                }
                catch (Exception)
                {
                    Util.ShowError("使用程序 命令行参数 配置服务器错误");
                    Console.ReadKey();
                    return;
                }
            }
            //本地调试
            else
            {
                var serverconf = Conf.SysServerList.Values.FirstOrDefault(p => p.ServerType == (int)默认服务器类型);
                if (serverconf == null)
                {
                    Util.ShowError("错误的服务器类型");
                    Console.ReadKey();
                    return;
                }
                BaseServerInfo.SessionType      = (EServerType)serverconf.ServerType;
                BaseServerInfo.ServerZoneSimple = $"{serverconf.Desc}";
                BaseServerInfo.ServerID         = serverconf.Id;
                Console.Title = BaseServerInfo.ServerZoneSimple;

                IPHostEntry ipe = Dns.GetHostEntry(Dns.GetHostName());
                IPAddress   ipa = ipe.AddressList[1];
                Util.Show($"服务器IP:{ipa.ToString()}:{BaseServerInfo.ServerID}");
                BaseServerInfo.ServerExtern = ipa.ToString();
            }
            BaseServerInfo.ServerZone = $"{BaseServerInfo.ServerZoneSimple} {BaseServerInfo.ServerID}";

            #endregion
            #region 初始化服务器

            //设置服务器
            if (!BaseServerInfo.AppServer.SetupEx(BaseServerInfo.ServerID, BaseServerInfo.ServerEncoding))
            {
                Util.ShowError("初始化失败!");
                Console.ReadKey();
                return;
            }

            #endregion 初始化服务器
        }
Beispiel #12
0
 /// <summary>
 ///    Sends the plan data as BufferChunk to server.
 /// </summary>
 /// <param name="data">The data.</param>
 /// <param name="server_type">Type of the server.</param>
 /// <returns><c>true</c> if OK, <c>false</c> otherwise.</returns>
 public virtual bool Send(BufferChunk data, EServerType server_type = EServerType.MCS)
 {
     return(Send((uint)data.Length, (byte[])data, server_type));
 }
Beispiel #13
0
 public Room(RoomCollection owner, EServerType serverType = EServerType.Game)
 {
     CreationTime = DateTime.Now;
     RoundStartTime = DateTime.Now;
     StartTime = DateTime.Now;
     RoomCollection = owner;
     ServerType = serverType;
 }
Beispiel #14
0
 private AsynchronousClient(EServerType _type)
 {
     type = _type;
 }
		public void Deserialize( Stream stream )
		{
			BinaryReader br = new BinaryReader( stream );

			JobidSent = br.ReadUInt64();
			EMsgSent = br.ReadUInt32();
			EServerTypeUnavailable = (EServerType)br.ReadInt32();
		}
Beispiel #16
0
        public void RefreshCachedData()
        {
            string      nHost         = data.Host;
            int         nPort         = data.Port;
            bool        nUsingSid     = data.UsingSid;
            string      nServiceName  = data.ServiceName;
            string      nInstanceName = data.InstanceName;
            string      nSid          = data.Sid;
            EServerType nServerType   = data.ServerType;

            if (nHost != host)
            {
                OnPropertyChanged("Host");
            }
            if (nPort != port)
            {
                OnPropertyChanged("Port");
            }
            if (nUsingSid != usingSid)
            {
                OnPropertyChanged("UsingSid");
            }

            if (nUsingSid)
            {
                if (nSid != sid)
                {
                    OnPropertyChanged("Sid");
                }

                if (!usingSid)
                {
                    OnPropertyChanged("ServiceName");
                    OnPropertyChanged("InstanceName");
                }
            }
            else
            {
                if (nServiceName != serviceName)
                {
                    OnPropertyChanged("ServiceName");
                }
                if (nInstanceName != instanceName)
                {
                    OnPropertyChanged("InstanceName");
                }

                if (usingSid)
                {
                    OnPropertyChanged("Sid");
                }
            }

            if (nServerType != serverType)
            {
                OnPropertyChanged("ServerType");
            }

            // nastav hodnoty
            host         = nHost;
            port         = nPort;
            usingSid     = nUsingSid;
            serviceName  = nServiceName;
            instanceName = nInstanceName;
            sid          = nSid;
            serverType   = nServerType;
        }
Beispiel #17
0
        public static void RunServer(Assembly assembly, EServerType serverType, ConfigInfo allConfig)
        {
            string serverTypeStr = "Lockstep.Server." + serverType.ToString().Replace("Server", "") + "." +
                                   (serverType).ToString();
            var type = assembly.GetType(serverTypeStr);

            if (type == null)
            {
                Console.WriteLine("StartServerFailed!: have no server type:" + serverTypeStr);
                return;
            }

            var        sobj   = Activator.CreateInstance(type);
            BaseServer server = sobj as BaseServer;

            if (server == null)
            {
                Console.WriteLine("RunServer failed sobj is not a BaseServer");
                return;
            }

            var  serverConfig = allConfig.GetServerConfig(serverType);
            long lastTick     = 1;
            int  tickInterval = 40;

            Console.WriteLine("=============== LockstepPlatform " + serverConfig.type + " Start!! ===============");
            Console.WriteLine("config: " + serverConfig.ToString());
            servers.Add(server);
            if (hasInited)
            {
                return;
            }

            hasInited = true;
            StartServices();

            var sw = new Stopwatch();

            sw.Start();
            {
                while (true)
                {
                    var count = servers.Count;
                    for (int i = 0; i < count; i++)
                    {
                        var svr = servers[i];
                        if (!svr.HasInit)
                        {
                            var initConfig =
                                allConfig.GetServerConfig((EServerType)(Enum.Parse(typeof(EServerType),
                                                                                   svr.GetType().Name)));
                            svr.DoAwake(initConfig);
                            svr.DoStart();
                        }
                    }

                    foreach (var svr in servers)
                    {
                        svr.PollEvents();
                    }

                    var curTick = sw.ElapsedMilliseconds;
                    var elapse  = curTick - lastTick;
                    if (elapse >= tickInterval)
                    {
                        lastTick = curTick;
                        UpdateServices();
                        foreach (var svr in servers)
                        {
                            svr.DoUpdate((int)elapse);
                        }
                    }

                    Thread.Sleep(1);
                }
            }
        }
Beispiel #18
0
 public ChannelCollection GetChannels(EServerType serverType)
 {
     var col = new ChannelCollection();
     using (var con = GetConnection())
     {
         using (var cmd = con.CreateCommand())
         {
             cmd.CommandText = "SELECT * FROM channels";
             using (var r = cmd.ExecuteReader())
             {
                 while (r.Read())
                 {
                     var channel = new Channel
                     {
                         ServerType = serverType,
                         ID = r.GetUInt16("ID"),
                         Name = r.GetString("Name")
                     };
                     col.TryAdd(channel.ID, channel);
                 }
             }
         }
     }
     return col;
 }
        /// <summary>
        /// 初始化指定类型的socket
        /// </summary>
        /// <param name="type">EServerType</param>
        /// <param name="ipp">SIpPort</param>
        public static void InitSocket(EServerType type, SIpPort ipp)
        {
            dicIPs[type] = ipp;

            dicClients[type] = AsynchronousClient.Create(type, ipp);
        }
Beispiel #20
0
        /// <summary>
        /// Returns the list of servers matching the given type
        /// </summary>
        /// <param name="type">Server type requested</param>
        /// <returns>List of server endpoints</returns>
        public List<IPEndPoint> GetServersOfType( EServerType type )
        {
            HashSet<IPEndPoint> set;
            if ( !serverMap.TryGetValue( type, out set ) )
                return new List<IPEndPoint>();

            return set.ToList();
        }
 /// <summary>
 /// 发送指定消息
 /// </summary>
 /// <param name="pk"></param>
 /// <param name="type"></param>
 public static void Send(PacketSend pk, EServerType type)
 {
     dicClients[type].Send(pk);
 }
Beispiel #22
0
        /// <summary>
        /// Returns the list of servers matching the given type
        /// </summary>
        /// <param name="type">Server type requested</param>
        /// <returns>List of server endpoints</returns>
        public List<IPEndPoint> GetServersOfType( EServerType type )
        {
            List<IPEndPoint> list;
            if ( !serverMap.TryGetValue( type, out list ) )
                return new List<IPEndPoint>();

            return list;
        }
 public void ReqStartServer(EServerType type)
 {
     //TODO 根据个Daemon 的cpu 占用决定究竟是哪一个改启动新的服务
     StartServer(type);
 }