Пример #1
0
        public WorldServer()
        {
            Config = new WorldServerConfig("Resources/Config/World.ini");

            WorldDatabase = new WorldDatabase(Config);
            if (WorldDatabase.Connection.CheckConnection())
            {
                Console.WriteLine("Connecting to cluster server...");

                int clusterPort    = (int)Config.GetSetting("ClusterPort");
                int worldStartPort = (int)Config.GetSetting("WorldStartPort");

                Console.WriteLine("Searching open port for cluster server communication...");
                while (PortChecker.IsPortAvailable(worldStartPort))
                {
                    Console.WriteLine("Port {0} not available, let's try another port", worldStartPort.ToString());
                    worldStartPort += 1;
                }

                ClusterConnector = new ClusterConnector(clusterPort.ToString(), worldStartPort.ToString());
                ClusterConnector.StartListening();

                // Let's wait a bit to let the subscriber and publisher socket to connect
                Thread.Sleep(1500);
                RegisterChannelRequest request = new RegisterChannelRequest((string)Config.GetSetting("ClusterAuthorizationPassword"), (string)Config.GetSetting("Address"), worldStartPort.ToString(), (string)Config.GetSetting("ChannelName"), 50, ClusterConnector.PublisherSocket);

                ClusterConnector.OnRegisterChannelSuccesful += new ClusterConnector.RequestSuccesfulHandler(OnRegisterChannelSuccesful);
            }
        }
Пример #2
0
        public static void RegisterChannelRequest(IncomingInterserverPacket packet)
        {
            RegisterChannelRequest request = new RegisterChannelRequest(packet);

            if (request.AuthorizationPassword != (string)ClusterServer.Config.GetSetting("ClusterAuthorizationPassword"))
            {
                Console.WriteLine("Couldn't register channel on this cluster");
                return;
            }

            Channel channel = new Channel();

            channel.ClientSocket               = new PushSocket(String.Format(">tcp://{0}:{1}", request.Ip, request.SendPort));
            channel.ChannelData                = new SharpFly_Packet_Library.Helper.Channel();
            channel.ChannelData.Id             = (uint)new Random().Next(10000, int.MaxValue);
            channel.ChannelData.Name           = request.Name;
            channel.ChannelData.PlayerCount    = 0;
            channel.ChannelData.MaxPlayerCount = request.MaxPlayerCount;

            ClusterServer.ChannelManager.AddChannel(channel);

            SharpFly_Packet_Library.Packets.Interserver.Outgoing.RegisterNewChannelRequest newChannelRequest = new SharpFly_Packet_Library.Packets.Interserver.Outgoing.RegisterNewChannelRequest(ClusterServer.ClusterId, channel.ChannelData.Id, request.AuthorizationPassword, request.Name, request.MaxPlayerCount, ClusterServer.LoginConnector.PublisherSocket);

            Console.WriteLine("Channel identified as {0}!", channel.ChannelData.Name);
        }
Пример #3
0
 public async Task RegisterChannel(string peerId, string channelId)
 {
     var request = new RegisterChannelRequest()
     {
         ChannelId = channelId,
         PeerdId   = peerId
     };
     await client.RegisterChannelAsync(request);
 }
Пример #4
0
        public override Task <RegisterChannelResponse> RegisterChannel(RegisterChannelRequest request, ServerCallContext context)
        {
            var channel  = tracker.AddChannel(request.PeerdId, request.ChannelId);
            var response = new RegisterChannelResponse()
            {
                ResponseStatus = ResponseHelpers.CreateOkStatus()
            };

            return(Task.FromResult(response));
        }