Esempio n. 1
0
        void StartServer()
        {
            ConsoleLogs.ConsoleLog(ConsoleColor.White,
                                   "Es ist Matchmaking 1 gebt den Server doch erstmal nen Like. Schreibs in die Kommentare findest du geil dann gibts bald Version 2");

            this.terminateServer = false;
            this.tcpListener     = new TcpListener(IPAddress.Any, SERVERPORT);

            try
            {
                tcpListener.Start();
                ConsoleLogs.ConsoleLog(ConsoleColor.Magenta, "Server Started");
            }
            catch (SocketException e)
            {
                ConsoleLogs.ConsoleLog(ConsoleColor.Red, e.ToString());
                throw;
            }

            this.serverThread = new Thread(this.ServerThreadProc);
            this.serverThread.IsBackground = true;
            this.serverThread.Start();

            rooms.Add(new Room("Lobby", Int32.MaxValue, true));
        }
Esempio n. 2
0
 private void Log(params object[] objs)
 {
     ConsoleLogs.Add(new JsLogggedVariables
     {
         LoggedOnUtc         = DateTime.UtcNow,
         SerializedVariables = objs?.Select(ToJsSerializedVariable).ToList() ?? new List <JsSerializedVariable>()
     });
 }
Esempio n. 3
0
        public void AddClient(Connection connection)
        {
            connection.MessageRecieved += OnMessageRecieved;
            this.connections.Add(connection);

            if (this == Server.instance.rooms[0])
            {
                SendRoomList(connection);
                return;
            }


            ClientInformationMessage m = new ClientInformationMessage(connection.ClientId, connection.Username, connections.Count - 1, 0);

            connection.Send(m);
            connection.PlayerID = connections.Count - 1;
            for (int i = 0; i < connections.Count; i++)
            {
                try
                {
                    m.informationType = 1;
                    if (connections[i] != connection)
                    {
                        connections[i].Send(m);
                    }
                    ClientInformationMessage m1 = new ClientInformationMessage(connections[i].ClientId, connections[i].Username, connections[i].PlayerID, 1);
                    connection.Send(m1);
                }
                catch (Exception e)
                {
                    ConsoleLogs.ConsoleLog(ConsoleColor.Red, e.ToString());
                    disconnectedConnections.Add(connections[i]);
                    connections[i].MessageRecieved -= OnMessageRecieved;
                }
            }

            if (this != Server.instance.rooms[0])
            {
                SendRoomInfo(connection);
                Console.WriteLine("ECH");
            }
        }
Esempio n. 4
0
        void RoomHeartbeatProc()
        {
            while (!terminateRoom)
            {
                for (int i = 0; i < connections.Count; i++)
                {
                    try
                    {
                        connections[i].Send(heartbeat);
                    }
                    catch (Exception e)
                    {
                        ConsoleLogs.ConsoleLog(ConsoleColor.Red, e.ToString());
                        disconnectedConnections.Add(connections[i]);
                        connections[i].MessageRecieved -= OnMessageRecieved;
                    }
                }

                HelperFunctions.RemoveDisconnectedClients(disconnectedConnections, connections);

                Thread.Sleep(3000);
            }
        }
Esempio n. 5
0
        public IActionResult Index()
        {
            if (_user != null)
            {
                ViewData["LoggeduserName"] = new List <string>()
                {
                    _user.UserFirstName + ' ' + _user.UserLastName, _user.UserImage
                };
            }

            ConsoleLogs consoleLogs = new ConsoleLogs(_env);

            using (GlobalDBContext context = new GlobalDBContext()) {
                //consoleLogs.WriteErrorLog(context.GeneratePath());



                //var WhatIsThis = _customAuthManager.Tokens.FirstOrDefault().Value.Item3;

                ViewBag.Message = "Looks like this is a ";
            }
            return(View());
        }
Esempio n. 6
0
        void OnMessageRecieved(MessageBase message, Connection senderConnection)
        {
            if (message is DisconnectMessage)
            {
                disconnectedConnections.Add(senderConnection);
                senderConnection.MessageRecieved -= OnMessageRecieved;
                HelperFunctions.RemoveDisconnectedClients(disconnectedConnections, connections);
                CheckRoomState();

                for (int i = 0; i < connections.Count; i++)
                {
                    ClientInformationMessage m = new ClientInformationMessage(connections[i].ClientId, connections[i].Username, i, 0);
                    connections[i].PlayerID = i;
                    connections[i].Send(m);
                }
            }

            if (message is ConnectMessage)
            {
                string clientID = (DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds.ToString() + "feral" + Server.instance.numOfConnectedClients;
                int    playerID = connections.Count - 1;

                ClientInformationMessage m = new ClientInformationMessage(clientID, ((ConnectMessage)message).userName, playerID, 0);
                senderConnection.Send(m);
                senderConnection.Username = ((ConnectMessage)message).userName;
                senderConnection.ClientId = clientID;
                senderConnection.PlayerID = playerID;

                if (this == Server.instance.rooms[0])
                {
                }
                else
                {
                    for (int i = 0; i < connections.Count; i++)
                    {
                        try
                        {
                            m.informationType = 1;
                            if (connections[i] != senderConnection)
                            {
                                connections[i].Send(m);
                            }
                            ClientInformationMessage m1 = new ClientInformationMessage(connections[i].ClientId, connections[i].Username, connections[i].PlayerID, 1);
                            senderConnection.Send(m1);
                        }
                        catch (Exception e)
                        {
                            ConsoleLogs.ConsoleLog(ConsoleColor.Red, e.ToString());
                            disconnectedConnections.Add(connections[i]);
                            connections[i].MessageRecieved -= OnMessageRecieved;
                        }
                    }
                }
            }

            if (message is RoomCreationMessage)
            {
                CreateRoom((RoomCreationMessage)message, senderConnection);
            }

            if (message is RoomJoinMessage)
            {
                var  m      = (RoomJoinMessage)message;
                Room target = FindRoom(m.roomID);

                if (target != null && !target.isLobby && target.playerCount < target.maxPlayerNumber)
                {
                    ((RoomJoinMessage)message).result = 0;
                    senderConnection.Send(message);
                    LeaveRoom(senderConnection, target);
                }
                else
                {
                    ((RoomJoinMessage)message).result = 1;
                    senderConnection.Send(message);
                }
            }

            if (message is RoomLobbyMessage)
            {
                var m = (RoomLobbyMessage)message;

                LeaveRoom(senderConnection);
                ((RoomLobbyMessage)message).result = 0;
                senderConnection.Send(message);
            }

            if (message is PlayerRenameMessage)
            {
                senderConnection.Username = ((PlayerRenameMessage)message).newName;
                if (senderConnection == connections[0])
                {
                    roomHost = ((PlayerRenameMessage)message).newName;
                }
            }

            if (message is RoomListUpdateMessage)
            {
                SendRoomList(senderConnection);
            }

            if (message.EMessageType != eMessageTypes.RoomJoinMessage)
            {
                for (int i = 0; i < connections.Count; i++)
                {
                    try
                    {
                        connections[i].Send(message);
                    }
                    catch (Exception e)
                    {
                        ConsoleLogs.ConsoleLog(ConsoleColor.Red, e.ToString());
                        disconnectedConnections.Add(connections[i]);
                        connections[i].MessageRecieved -= OnMessageRecieved;
                    }
                }
            }

            ConsoleLogs.LogMessage(message);
        }