Example #1
0
 public void Configuration(IAppBuilder app)
 {
     // Weitere Informationen zum Konfigurieren Ihrer Anwendung finden Sie unter https://go.microsoft.com/fwlink/?LinkID=316888.
     // NuGet Microsoft.AspNet.SignalR
     //       Microsoft.AspNet.SignalR.SelfHost
     //       Microsoft.EntityFrameworkCore.Sqlite
     app.MapSignalR();
     ChatServerContext.Init();
 }
Example #2
0
        // Put: api/Messages
        public void Put([FromBody] MessageStateModification messageState)
        {
            var message = ChatServerContext.Messages.FirstOrDefault(m => m.MessageGuid == messageState.MessageGuid);

            if (message != null)
            {
                message.State = messageState.MessageState;
                hubContext.Clients.Client(message.From.ConnectionGuid).ReceiveMessageStateModification(messageState);
            }

            ChatServerContext.SaveChanges();
        }
        // POST: api/Register
        public User Post([FromBody] string userName)
        {
            User output = new User
            {
                Nickname = userName,
                UserGuid = Guid.NewGuid().ToString()
            };

            ChatServerContext.Users.Add(output);
            ChatServerContext.SaveChanges();

            return(output);
        }
Example #4
0
        public Server(string identifier, ChatServerContext context)
            : base(identifier, context)
        {
            if (Hostname == null) {
                Hostname = Context.Config.Get("Chat.Protocols.IRC", "Hostname", "irc.flash.moe");
            }

            Log = new Logger($"IRC Server ({Identifier})");

            short bindPort = Context.Config.Get<short>("Chat.Protocols.IRC", "Port", 6667);
            Listener = new TcpListener(IPAddress.Any, bindPort);
            Log.Write(LogSeverity.Info, "Creating IRC server on port {0}.", bindPort.ToString());
        }
        // POST: api/Login
        public void Post([FromBody] User user)
        {
            var searchUser = ChatServerContext.GetUser(user.UserGuid);

            if (searchUser == null)
            {
                ChatServerContext.Users.Add(user);
                ChatServerContext.SaveChanges();
            }

            IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext <ChatHub>();

            hubContext.Clients.Client(user.ConnectionGuid).Hello();
        }
Example #6
0
        public Server(string identifier, ChatServerContext context)
            : base(identifier, context)
        {
            Log = new Logger($"Sock Chat Server ({Identifier})");

            short bindPort = Context.Config.Get<short>("Chat.Protocols.SockChat", "Port", 6770);

            Log.Write(LogSeverity.Info, "Creating SockLegacy server on port {0}.", bindPort.ToString());

            Socket = new WebSocketServer(bindPort);
            Socket.AddWebSocketService(Endpoint, () => {
                return new Service(Context);
            });
        }
Example #7
0
        public override Task OnConnected()
        {
            var connectionGuid = Context.ConnectionId;
            var userGuid       = Context.Headers.Get(Constants.UserGuid);

            var searchUser = ChatServerContext.GetUser(userGuid);

            if (searchUser != null)
            {
                searchUser.ConnectionGuid = connectionGuid;
                ChatServerContext.SaveChanges();
            }

            return(base.OnConnected());
        }
Example #8
0
        // POST: api/Messages
        public void Post([FromBody] Message message)
        {
            DataContext.Instance.Context.Messages.Add(message);

            ChatServerContext.Messages.Add(message);
            ChatServerContext.SaveChanges();

            var messageState = new MessageStateModification {
                MessageGuid = message.MessageGuid, MessageState = MessageState.OnServer
            };

            hubContext.Clients.Client(message.From.ConnectionGuid).ReceiveMessageStateModification(messageState);

            var conGuid = ChatServerContext.Users.FirstOrDefault(u => u.UserGuid == message.ToGuid)?.ConnectionGuid;

            if (conGuid != null)
            {
                hubContext.Clients.Client(conGuid).ReceivePrivateMessage(message);
            }
        }
Example #9
0
 public Server(string identifier, ChatServerContext context)
     : base(identifier, context)
 {
 }
Example #10
0
 public ServerProtocol(string identifier, ChatServerContext context)
 {
     Identifier = identifier;
     Context = context;
 }
Example #11
0
 public Service(ChatServerContext context)
     : base()
 {
     ServerContext = context;
     AuthClient = new AuthClient(context.Config);
 }