Ejemplo n.º 1
0
        public void Init()
        {
            ServerCommandLine.Instance.Init();
            ResControl.Instance.Init();
            NodeControl.Instance.Init();
            EntityContent.Instance.Init();

            IPEndPoint point = UdpConfig.DnsToIPEndPoint(Config.primarilyIp);

            if (point == null)
            {
                Server = new UdpPoint(Config.primarilyPort, false);
            }
            else
            {
                Server = new UdpPoint(point, false);
            }

            m_isBroadcast = Config.isEnableBroadcast;
            //最大存储1000帧指令
            MaxQueueBuffer = 1000;
            //缓存队列计数
            QueueBufferCount = 0;
            //设置一个随机验证值
            LocalNetNode.license = random.Next();
            //新的服务器信息
            HostInfo             = new ServerInfo();
            HostInfo.name        = Config.name;
            HostInfo.description = Config.description;
            //服务端启动时间
            //StartTickTime = RealityTickTime;
            Console.WriteLine("[Server状态机执行初始化]" + IsBroadcast);

            Server.Mgr.OnRequestDataHandle += NetRequestData.OnRequestDataServer;
            Server.Mgr.OnCmdDataHandle     += NetCmdData.OnCmdDataServer;
            Server.Mgr.OnReadBufferHandle  += NetReadBuffer.OnReadBufferServer;
            Server.Mgr.OnRequestCmdHandle  += NetRequestCmd.OnRequestCmdServer;

            //Console.WriteLine(Server.LocalEndPoint);
        }
Ejemplo n.º 2
0
        void IsConnectArgument(CommandLineArgumentParser arguments, ref int valid)
        {
            if (arguments.StartWith("/connect"))
            {
                if (arguments.Has("-t"))
                {
                    ServerInfo info = null;
                    if (arguments.Has("-f"))
                    {
                        foreach (var item in NetControl.Instance.ServerInfoDic)
                        {
                            if (item.Value.isValid)
                            {
                                info = item.Value;
                                NetControl.Instance.TryServerConnectTest(info);
                                valid += 1; return;
                            }
                        }
                        Console.WriteLine("未找到任何服务端");
                        valid += 1; return;
                    }
                    else
                    {
                        CommandLineArgument node = arguments.Get("-t");
                        if (node.Take() != null && node.Take() != "")
                        {
                            string     ip    = node.Take();
                            IPEndPoint point = UdpConfig.StrParseToIp(ip);
                            if (point == null)
                            {
                                point = UdpConfig.DnsToIPEndPoint(ip);
                            }
                            if (point != null)
                            {
                                NetControl.Instance.TryServerConnectTest(point);
                                valid += 1; return;
                            }
                            else
                            {
                                Console.WriteLine("无效的网络地址");
                                valid += 1; return;
                            }
                        }
                    }

                    if (info != null)
                    {
                        NetControl.Instance.TryServerConnectTest(info);
                    }
                    else
                    {
                        Console.WriteLine("未选择任何服务端");
                    }
                    valid += 1;
                    return;
                }
                if (arguments.Has("-c"))
                {
                    ServerInfo info = NetControl.Instance.CurrentConnectHost;
                    if (info != null)
                    {
                        NetControl.Instance.TryCanelConnectHost();
                    }
                    else
                    {
                        Console.WriteLine("未连接任何服务端");
                    }
                    valid += 1; return;
                }
                if (arguments.Has("-f"))
                {
                    foreach (var item in NetControl.Instance.ServerInfoDic)
                    {
                        if (item.Value.isValid)
                        {
                            NetControl.Instance.TryConnectHost(item.Value);
                            valid += 1; return;
                        }
                    }
                    Console.WriteLine("未找到任何服务端");
                    valid += 1; return;
                }
                if (arguments.Has("-i"))
                {
                    ServerInfo info = NetControl.Instance.CurrentConnectHost;
                    if (info != null)
                    {
                        Console.WriteLine("[n]" + info.name + "[d]" + info.description + "[r]" + info.remote + "[is]" + info.isSync + ":" + NodeControl.Instance.LocalPlayer.serial + "" + "[ic]" + info.isConnect + "[iv]" + info.isValid + "[io]" + info.isOvertime + "[nc]" + info.currentConnectNodeCount + "[mc]" + info.maxConnectNodeCount + "[ot]" + (TimeControl.TickTime - info.lastTime) + "ms");
                    }
                    else
                    {
                        Console.WriteLine("未连接任何服务端");
                    }
                    valid += 1;
                }
                Console.WriteLine("输入参考:\n参数 -c 取消当前连接\n参数 -f 连接第一个有效的服务端\n参数 -i 查看当前连接信息\n参数 -t[address] 尝试获取服务端信息");
                valid += 1;
            }
            else
            {
                return;
            }
        }