Beispiel #1
0
        public ClientThread(IChatServer chatServer, ChatClient chatClient)
        {
            ChatServer = chatServer;
            ChatClient = chatClient;

            new Thread(new ThreadStart(StartChat)).Start();
        }
Beispiel #2
0
        public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e)
        {
            if (e.SourceException == null)
            {
                Console.WriteLine("Global event: {0}\r\nUrl: {1}", e.EventType,
                                  e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString());
            }
            else
            {
                Console.WriteLine("Global event: {0}\r\nUrl: {1}\r\nException: {2}", e.EventType,
                                  e.HostInformation == null ? "<not specified>" : e.HostInformation.ToString(),
                                  e.SourceException);
            }

            if (e.EventType == GenuineEventType.GeneralServerRestartDetected)
            {
                // server has been restarted so it does not know that we need messages and ours nickname
                lock (ChatClient.IChatServerLock)
                {
                    ChatClient.IChatServer = (IChatServer)Activator.GetObject(typeof(IChatRoom),
                                                                              ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem");
                    ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                }
            }
        }
Beispiel #3
0
 public MainWindow()
 {
     InitializeComponent();
     //pass the new client callback function created class and endpoint name
     _channelFactory  = new DuplexChannelFactory <IChatServer>(new CallBackFxn(), "ChattingServiceEndpoint");
     _serviceContract = _channelFactory.CreateChannel();
 }
Beispiel #4
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            ChatClientServices.form = this;
            int        port = Int32.Parse(tb_Port.Text);
            TcpChannel chan = new TcpChannel(port);

            ChannelServices.RegisterChannel(chan, false);

            // Alternative 1 for service activation
            ChatClientServices servicos = new ChatClientServices();

            RemotingServices.Marshal(servicos, "ChatClient",
                                     typeof(ChatClientServices));

            // Alternative 2 for service activation
            //RemotingConfiguration.RegisterWellKnownServiceType(
            //    typeof(ChatClientServices), "ChatClient",
            //    WellKnownObjectMode.Singleton);

            IChatServer   server   = (IChatServer)Activator.GetObject(typeof(IChatServer), "tcp://localhost:8086/ChatServer");
            List <string> messages = server.RegisterClient(port.ToString());

            this.server = server;
            foreach (object o in messages)
            {
                AddMsg((string)o);
            }
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FriendServer" /> class.
 /// </summary>
 /// <param name="gameServers">The game servers.</param>
 /// <param name="chatServer">The chat server.</param>
 /// <param name="repositoryManager">The repository manager.</param>
 public FriendServer(IDictionary <int, IGameServer> gameServers, IChatServer chatServer, IRepositoryManager repositoryManager)
 {
     this.chatServer        = chatServer;
     this.GameServers       = gameServers;
     this.repositoryManager = repositoryManager;
     this.OnlineFriends     = new Dictionary <string, OnlineFriend>();
 }
Beispiel #6
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            if (nickTextBox.Text != "" && portTextBox.Text != "")
            {
                nick = nickTextBox.Text;
                port = Convert.ToInt32(portTextBox.Text);

                // Iniciar canal
                channel = new TcpChannel(port);
                ChannelServices.RegisterChannel(channel, false);

                // Registro do Servidor
                server = (IChatServer)Activator.GetObject(
                    typeof(IChatServer),
                    "tcp://localhost:8086/ChatServer" //lacking null verification
                    );

                // Registro do cliente
                RemoteChatClient rmc = new RemoteChatClient(this);
                String           clientServiceName = "ChatClient";
                RemotingServices.Marshal(
                    rmc,
                    clientServiceName,
                    typeof(RemoteChatClient)
                    );

                if (server != null)
                {
                    // opcional
                    server.connect(nick, "tcp://localhost:" + port + "/" + clientServiceName);
                }
            }
        }
Beispiel #7
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            if (nickTextBox.Text != "" && portTextBox.Text != "")
            {
                nick = nickTextBox.Text;
                port = Convert.ToInt32(portTextBox.Text);

                // Iniciar canal
                channel = new TcpChannel(port);
                ChannelServices.RegisterChannel(channel, false);

                // Registro do Servidor
                server = (IChatServer)Activator.GetObject(
                    typeof(IChatServer),
                    "tcp://localhost:8086/ChatServer" //lacking null verification
                );

                // Registro do cliente
                RemoteChatClient rmc = new RemoteChatClient(this);
                String clientServiceName = "ChatClient";
                RemotingServices.Marshal(
                    rmc,
                    clientServiceName,
                    typeof(RemoteChatClient)
                );

                if (server != null)
                {
                    // opcional
                    server.connect(nick, "tcp://localhost:" + port + "/" + clientServiceName);
                }
            }
        }
Beispiel #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FriendServer" /> class.
 /// </summary>
 /// <param name="gameServers">The game servers.</param>
 /// <param name="chatServer">The chat server.</param>
 /// <param name="persistenceContextProvider">The persistence context provider.</param>
 public FriendServer(IDictionary <int, IGameServer> gameServers, IChatServer chatServer, IPersistenceContextProvider persistenceContextProvider)
 {
     this.chatServer  = chatServer;
     this.GameServers = gameServers;
     this.persistenceContextProvider = persistenceContextProvider;
     this.OnlineFriends = new Dictionary <string, OnlineFriend>();
 }
Beispiel #9
0
 public void Disconnect(IChatServer server)
 {
     if (server != null)
     {
         server.HandleDisconnectRequest(this);
     }
 }
Beispiel #10
0
 public void ConnectTo(IChatServer server)
 {
     if (server != null)
     {
         server.HandleConnectRequest(this);
     }
 }
Beispiel #11
0
        public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e)
        {
            if (e.SourceException == null)
            {
                Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}",
                                  e.EventType,
                                  e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString());
            }
            else
            {
                Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}\r\nException: {2}",
                                  e.EventType,
                                  e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString(),
                                  e.SourceException);
            }

            if (e.EventType == GenuineEventType.GeneralServerRestartDetected)
            {
                // server has been restarted so it does not know that we have been subscribed to
                // messages and ours nickname
                lock (ChatClient.IChatServerLock)
                {
                    ChatClient.IChatServer = (IChatServer)Activator.GetObject(typeof(IChatRoom),
                                                                              RemoteHostUri + "/ChatServer.rem");
                    ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                }
            }
        }
Beispiel #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExDbClient" /> class.
 /// </summary>
 /// <param name="host">The host address of the exDB server.</param>
 /// <param name="port">The host port of the exDB server.</param>
 /// <param name="chatServer">The chat server.</param>
 /// <param name="chatServerPort">The chat server port.</param>
 public ExDbClient(string host, int port, IChatServer chatServer, int chatServerPort)
 {
     this.host           = host;
     this.port           = port;
     this.chatServer     = chatServer;
     this.chatServerPort = (ushort)chatServerPort;
     Task.Run(async() => await this.Connect());
 }
Beispiel #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExDbClient" /> class.
 /// </summary>
 /// <param name="host">The host address of the exDB server.</param>
 /// <param name="port">The host port of the exDB server.</param>
 /// <param name="chatServer">The chat server.</param>
 /// <param name="chatServerPort">The chat server port.</param>
 /// <param name="loggerFactory">The logger factory.</param>
 public ExDbClient(string host, int port, IChatServer chatServer, int chatServerPort, ILoggerFactory loggerFactory)
 {
     this.host           = host;
     this.port           = port;
     this.chatServer     = chatServer;
     this.loggerFactory  = loggerFactory;
     this.chatServerPort = (ushort)chatServerPort;
     this.logger         = this.loggerFactory.CreateLogger <ExDbClient>();
     Task.Run(async() => await this.Connect().ConfigureAwait(false));
 }
Beispiel #14
0
        /// <summary>
        /// Creates a new instance of the <see cref="MmoChat"/> class.
        /// </summary>
        /// <param name="server"></param>
        private MmoChat(IChatServer server)
        {
            this.server       = server;
            this.channels     = new ConcurrentStorageMap <int, Channel>(PeerSettings.MaxLockWaitTime);
            this.sessionCache = new ChatSessionCache(PeerSettings.MaxLockWaitTime);
            this.counter      = new Counter(INVALID_CHAT_CHANNEL + 1);

            this.syncFiber = new SerialThreadFiber(ThreadPriority.Highest);
            this.syncFiber.Start();
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            // wait for the server
            Console.WriteLine("Sleep for 3 seconds.");
            Thread.Sleep(TimeSpan.FromSeconds(3));

            // setup .NET Remoting
            Console.WriteLine("Configuring Remoting environment...");
            System.Configuration.ConfigurationSettings.GetConfig("DNS");
            GenuineGlobalEventProvider.GenuineChannelsGlobalEvent += new GenuineChannelsGlobalEventHandler(GenuineChannelsEventHandler);
            RemotingConfiguration.Configure("Client.exe.config");
            //GlobalLoggerContainer.Logger = new BinaryLog(@"c:\tmp\client.log");

            Console.WriteLine(".NET Remoting has been configured from Client.exe.config file.");

            Console.WriteLine("Please enter a nickname:");
            ChatClient.Nickname = Console.ReadLine();

            // bind client's receiver
            RemotingServices.Marshal(ChatClient.Instance, "MessageReceiver.rem");

            for (;;)
            {
                try
                {
                    // subscribe to the chat event
                    lock (ChatClient.IChatServerLock)
                    {
                        ChatClient.IChatServer = (IChatServer)Activator.GetObject(typeof(IChatRoom),
                                                                                  ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem");
                        ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                    }

                    for (;;)
                    {
                        Console.WriteLine("Enter a message to send or an empty string to exit.");

                        string str = Console.ReadLine();
                        if (str.Length <= 0)
                        {
                            return;
                        }

                        ChatClient.IChatRoom.SendMessage(str);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace);
                }

                Console.WriteLine("Next attempt to connect to the server will be in 3 seconds.");
                Thread.Sleep(3000);
            }
        }
 public DiscordChatChannel(IChannel channel)
 {
     Id       = channel.Id;
     _channel = channel;
     if (channel is SocketGuildChannel)
     {
         var guildChannel = (SocketGuildChannel)channel;
         Name   = guildChannel.Name;
         Server = new DiscordChatServer(guildChannel.Guild);
     }
 }
Beispiel #17
0
        /// <summary>
        /// Creates a new instance of the <see cref="ChatSession"/> class,
        /// </summary>
        public ChatSession(int sessionId, string name, IChatServer server, MmoChat chat)
        {
            this.server    = server;
            this.chat      = chat;
            this.sessionId = sessionId;
            this.name      = name;

            this.joinedChannels = new List <IChannel>();
            this.SessionState   = ChatSessionState.Login;

            this.chat.SyncFiber.Enqueue(DoAddSession);
        }
 public ChatServer(ILogger <ChatServer> logger,
                   IChatUserIdentityProvider identityProvider,
                   IMessageProtocol messageProtocol,
                   IChatServer chatServer,
                   IRoomRegistry roomRegistry)
 {
     this.logger           = logger;
     this.messageProtocol  = messageProtocol;
     this.chatServer       = chatServer;
     this.roomRegistry     = roomRegistry;
     this.identityProvider = identityProvider;
 }
Beispiel #19
0
        static void Main(string[] args)
        {
            Console.WriteLine("Sleep for 3 seconds.");
            Thread.Sleep(TimeSpan.FromSeconds(3));

            Console.WriteLine("Configuring Remoting environment...");
            System.Configuration.ConfigurationSettings.GetConfig("DNS");
            GenuineGlobalEventProvider.GenuineChannelsGlobalEvent += new GenuineChannelsGlobalEventHandler(GenuineChannelsEventHandler);
            RemotingConfiguration.Configure("Client.exe.config");

            Console.WriteLine(".NET Remoting has been configured from Client.exe.config file.");

            Console.WriteLine("Please enter nickname of this client:");
            ChatClient.Nickname = Console.ReadLine();

            //**** Attach a receiver to the court
            IReturnItself iReturnItself = (IReturnItself)Activator.GetObject(typeof(IChatRoom),
                                                                             ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ReturnItself.rem");

            CourtCollection.Attach("/Chat/GlobalRoom", ChatClient.Instance, iReturnItself.ReturnItself());

            for (;;)
            {
                try
                {
                    IChatServer iChatServer = (IChatServer)Activator.GetObject(typeof(IChatServer),
                                                                               ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem");
                    ChatClient.IChatRoom = iChatServer.EnterToChatRoom(ChatClient.Instance, ChatClient.Nickname);

                    for (;;)
                    {
                        Console.WriteLine("Enter a message to send or an empty string to exit.");

                        string str = Console.ReadLine();
                        if (str.Length <= 0)
                        {
                            return;
                        }

                        ChatClient.IChatRoom.SendMessage(str);
                        Console.WriteLine("Message \"{0}\" has been sent.", str);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace);
                }

                Console.WriteLine("Next attempt to connect to the server will be in 3 seconds.");
                Thread.Sleep(3000);
            }
        }
Beispiel #20
0
 public ProtoV3ChatWorker(IChatServer server, TcpClient connection)
 {
     this.server     = server;
     this.connection = connection;
     try
     {
         stream    = connection.GetStream();
         connected = true;
     }
     catch (Exception e)
     {
         Console.WriteLine(e.StackTrace);
     }
 }
        public ChatServer(ILogger <ChatServer> logger,
                          IOptions <ServerConfig> serverConfig,
                          IChatUserIdentityProvider identityProvider,
                          IMessageProtocol messageProtocol,
                          IChatServer chatServer,
                          IRoomRegistry roomRegistry)
        {
            this.logger           = logger;
            this.messageProtocol  = messageProtocol;
            this.chatServer       = chatServer;
            this.roomRegistry     = roomRegistry;
            this.identityProvider = identityProvider;
            var listeningConfig = serverConfig.Value.Listening;
            var listeningHost   = IPAddress.Parse(listeningConfig.Host);
            var listeningPort   = listeningConfig.Port;

            this.listener = new TcpListener(listeningHost, listeningPort);
            this.tracker  = new TaskTracker();
        }
Beispiel #22
0
        private void CreateConnection()
        {
            try
            {
                if (_channel != null && _channel.State == CommunicationState.Opened)
                {
                    return;
                }

                var adres = new Uri("http://localhost:2222/");
                _channel = new DuplexChannelFactory <IChatServer>(new InstanceContext(new ChatClientService
                {
                    AppendMessage = ReceiveMessage,
                    RefreshUsers  = RefreshUsers
                }), new WSDualHttpBinding(), new EndpointAddress(adres));
                _service = _channel.CreateChannel();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Błąd połączenia", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public static void GenuineChannelsEventHandler(object sender, GenuineEventArgs e)
        {
            if (e.SourceException == null)
                Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}",
                    e.EventType,
                    e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString());
            else
                Console.WriteLine("\r\n\r\n---Global event: {0}\r\nRemote host: {1}\r\nException: {2}",
                    e.EventType,
                    e.HostInformation == null ? "<unknown>" : e.HostInformation.ToString(),
                    e.SourceException);

            if (e.EventType == GenuineEventType.GeneralServerRestartDetected)
            {
                // server has been restarted so it does not know that we have been subscribed to
                // messages and ours nickname
                lock(ChatClient.IChatServerLock)
                {
                    ChatClient.IChatServer = (IChatServer) Activator.GetObject(typeof(IChatRoom),
                        ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem");
                    ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                }
            }
        }
Beispiel #24
0
 public ProtoV3ChatServer(string host, int port, IChatServer server)
     : base(host, port)
 {
     this.server = server;
     Console.WriteLine("ProtoChatServer...");
 }
Beispiel #25
0
 public MockedChatChannel(ChatTypes?chatType = null, ulong id = 0, string name = null, IChatServer server = null)
 {
     ChatType = chatType.HasValue ? chatType.Value : ChatTypes.Discord;
     Id       = id;
     Name     = name;
     Server   = server ?? new MockedChatServer(ChatType);
 }
Beispiel #26
0
 public HumanChatWindow(IChatServer server)
 {
     _server = server;
 }
Beispiel #27
0
        static void Main(string[] args)
        {
            enumGC_Mode GC_Mode = enumGC_Mode.GC_HTTP;

            // setup .NET Remoting
            Console.WriteLine("Configuring Remoting environment...");
            //System.Configuration.ConfigurationSettings.GetConfig("DNS");
            GenuineGlobalEventProvider.GenuineChannelsGlobalEvent += new GenuineChannelsGlobalEventHandler(GenuineChannelsEventHandler);

            IDictionary props = new Hashtable();

            switch (GC_Mode)
            {
            case enumGC_Mode.GC_TCP:
                Console.WriteLine("GC_TCP Client connecting to Server...");
                GenuineTcpChannel channelTCP = new GenuineTcpChannel(props, null, null);
                ChannelServices.RegisterChannel(channelTCP, false);

                RemoteHostUri       = "gtcp://127.0.0.1:8737";
                ChatClient.Nickname = "GC_TCP_ChatClient";
                break;

            case enumGC_Mode.GC_HTTP:
                Console.WriteLine("GC_HTTP Client connecting to Server...");
                props["name"]     = "ghttp";
                props["priority"] = "100";
                GenuineHttpClientChannel channelHttp = new GenuineHttpClientChannel(props, null, null);
                ChannelServices.RegisterChannel(channelHttp, false);

                RemoteHostUri       = "ghttp://localhost:49834"; // Note the full address will be determined by the server
                ChatClient.Nickname = "GC_HTTP_ChatClient";
                break;
            }

            // bind client's receiver
            RemotingServices.Marshal(ChatClient.Instance, "MessageReceiver.rem");
            for (;;)
            {
                try
                {
                    // subscribe to the chat event
                    lock (ChatClient.IChatServerLock)
                    {
                        ChatClient.IChatServer = (IChatServer)Activator.GetObject(typeof(IChatRoom),
                                                                                  RemoteHostUri + "/ChatServer.rem");
                        ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                    }

                    for (;;)
                    {
                        Console.WriteLine("Enter a message to send or an empty string to exit.");

                        string str = Console.ReadLine();
                        if (str.Length <= 0)
                        {
                            return;
                        }

                        ChatClient.IChatRoom.SendMessage(str);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\r\n\r\n---Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace);
                }

                Console.WriteLine("Next attempt to connect to the server will be in 3 seconds.");
                Thread.Sleep(3000);
            }
        }
Beispiel #28
0
        static void Join(object sender, JoinEventArgs e)
        {
            TcpChannel channelServ = new TcpChannel(Convert.ToInt32(e.Port));
            ChannelServices.RegisterChannel(channelServ, true);
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(ChatClient), Constants.REMOTE_CLIE_OBJ_NAME, WellKnownObjectMode.Singleton);

            server = (IChatServer)Activator.GetObject(typeof(IChatServer), Constants.SERVER_URL);

            server.join(e.Nickname, URLGenerator.generate(e.Port, Constants.REMOTE_CLIE_OBJ_NAME));
        }
Beispiel #29
0
        public Form1()
        {
            InitializeComponent();

            _chatServer = new ChatServer(8001);
        }
Beispiel #30
0
 /// <summary>
 /// Instantiates the singleton of the <see cref="MmoChat"/>. If it has already been instantiated returns the old instance.
 /// </summary>
 public static MmoChat Instantiate(IChatServer server)
 {
     lock (typeof(MmoChat))
         return(Instance ?? (Instance = new MmoChat(server)));
 }
        static void Main(string[] args)
        {
            // wait for the server
            Console.WriteLine("Sleep for 3 seconds.");
            Thread.Sleep(TimeSpan.FromSeconds(3));

            // setup .NET Remoting
            Console.WriteLine("Configuring Remoting environment...");
            System.Configuration.ConfigurationSettings.GetConfig("DNS");
            GenuineGlobalEventProvider.GenuineChannelsGlobalEvent += new GenuineChannelsGlobalEventHandler(GenuineChannelsEventHandler);
            //GlobalLoggerContainer.Logger = new BinaryLog(@"c:\tmp\client.log", false);
            RemotingConfiguration.Configure("Client.exe.config");

            Console.WriteLine(".NET Remoting has been configured from Client.exe.config file.");

            Console.WriteLine("Please enter a nickname:");
            ChatClient.Nickname = Console.ReadLine();

            // bind client's receiver
            RemotingServices.Marshal(ChatClient.Instance, "MessageReceiver.rem");

            for(;;)
            {
                try
                {
                    // subscribe to the chat event
                    lock(ChatClient.IChatServerLock)
                    {
                        ChatClient.IChatServer = (IChatServer) Activator.GetObject(typeof(IChatRoom),
                            ConfigurationSettings.AppSettings["RemoteHostUri"] + "/ChatServer.rem");
                        ChatClient.IChatRoom = ChatClient.IChatServer.EnterToChatRoom(ChatClient.Nickname);
                    }

                    for(;;)
                    {
                        Console.WriteLine("Enter a message to send or an empty string to exit.");

                        string str = Console.ReadLine();
                        if (str.Length <= 0)
                            return ;

                        ChatClient.IChatRoom.SendMessage(str);
                    }
                }
                catch(Exception ex)
                {
                    Console.WriteLine("\r\n\r\n---Exception: {0}. Stack trace: {1}.", ex.Message, ex.StackTrace);
                }

                Console.WriteLine("Next attempt to connect to the server will be in 3 seconds.");
                Thread.Sleep(3000);
            }
        }
 public MockedChatMessage(string content, ChatTypes?chatType = null, IChatUser user = null, IChatChannel channel = null, IChatServer server = null)
 {
     Content  = content;
     ChatType = chatType.HasValue ? chatType.Value : ChatTypes.Discord;
     User     = user ?? new MockedChatUser(ChatType);
     Channel  = channel ?? new MockedChatChannel(ChatType);
     Server   = server ?? new MockedChatServer(ChatType);
 }
 public ChatClientCtrl(IChatServer server)
 {
     this.server = server;
     currentUser = null;
 }