Example #1
0
        public static bool LoadRoom(PlayerRoom room, int index)
        {
            using var ofd = new OpenFileDialog
                  {
                      Filter   = "New Horizons Player House Room (*.nhpr)|*.nhpr|All files (*.*)|*.*",
                      FileName = $"Room {index + 1}.nhpr",
                  };
            if (ofd.ShowDialog() != DialogResult.OK)
            {
                return(false);
            }

            var       file         = ofd.FileName;
            var       fi           = new FileInfo(file);
            const int expectLength = PlayerRoom.SIZE;

            if (fi.Length != expectLength)
            {
                WinFormsUtil.Error(MessageStrings.MsgCanceling, string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expectLength));
                return(false);
            }

            var data = File.ReadAllBytes(file);

            data.CopyTo(room.Data, 0);
            return(true);
        }
        // <challenge name="AeonLucid" hash="xxxxxx" />
        public void HandleMessage(IncomingMessage message, ClientHandler clientHandler)
        {
            var name = message.Document?.Attribute("name")?.Value;

            if (name == null)
            {
                clientHandler.Disconnect("Invalid MessageEventChallenge received.");
                return;
            }

            if (string.Equals(name, clientHandler.Username))
            {
                Logger.Error($"Received self challenge from {name}..?");
                return;
            }

            if (!PlayerRoom.HasPlayer(name))
            {
                return;
            }

            var player = PlayerRoom.GetPlayer(name);

            if (player.State == PlayerState.Lobby)
            {
                clientHandler.GetPlayer().ChallengePlayer(player);
            }
        }
        // <msgAll name="AeonLucid" msg="hallo  " />
        public void HandleMessage(IncomingMessage message, ClientHandler clientHandler)
        {
            var name = message.Document?.Attribute("name")?.Value;

            if (name == null || !name.Equals(clientHandler.Username))
            {
                // Spoof attempt
                return;
            }

            var chatMessage = message.Document?.Attribute("msg")?.Value;

            if (chatMessage == null)
            {
                // Empty chat message
                return;
            }

            if (chatMessage.Length > 70)
            {
                chatMessage = chatMessage.Substring(0, 70);
            }

            PlayerRoom.SendChatMessage(clientHandler.Username, chatMessage);
        }
        public async Task <IActionResult> PutPlayerRoom(int id, PlayerRoom playerRoom)
        {
            if (id != playerRoom.PlayerId)
            {
                return(BadRequest());
            }

            _context.Entry(playerRoom).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlayerRoomExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
        public Player GetPlayer()
        {
            if (Username == null)
            {
                throw new NullReferenceException("Username was not set.");
            }

            return(PlayerRoom.GetPlayer(Username));
        }
Example #6
0
        private void ReceiveDataCallback(IAsyncResult ar)
        {
            if (ClientSocket == null || !ClientSocket.Connected || Disposing)
            {
                return;
            }

            try
            {
                var bytesReceived = ClientSocket.EndReceive(ar);
                if (bytesReceived == 0)
                {
                    Logger.Info($"[{Username ?? "Anonymous"}] has disconnected from the server.");

                    if (Username != null)
                    {
                        PlayerRoom.RemovePlayer(Username);
                    }

                    Disconnect();
                    return;
                }

                var packetBytes = new byte[bytesReceived];
                Buffer.BlockCopy(SocketBuffer, 0, packetBytes, 0, bytesReceived);

                try
                {
                    var packetString = Encoding.Default.GetString(packetBytes);
                    var packetXml    = XElement.Parse(packetString.Substring(0, packetString.Length - 1)); // TODO: Make sure entire packet is here /0
                    if (packetXml.Name.LocalName.Equals("policy-file-request"))
                    {
                        Logger.Debug("Received policy request");

                        ClientSocket.Send(Encoding.Default.GetBytes(CrossDomainPolicy.GetPolicy()));
                    }
                    else
                    {
                        PacketHandler.HandleIncomingMessage(new IncomingMessage(packetXml), this);
                    }
                }
                catch (XmlException)
                {
                    // ignored
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, "Client generated an exception.");
            }
            finally
            {
                ReceiveData();
            }
        }
Example #7
0
        public static void DumpRoom(PlayerRoom room, int index)
        {
            using var sfd = new SaveFileDialog
                  {
                      Filter   = "New Horizons Player House Room (*.nhpr)|*.nhpr|All files (*.*)|*.*",
                      FileName = $"Room {index + 1}.nhpr",
                  };
            if (sfd.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var data = room.Data;

            File.WriteAllBytes(sfd.FileName, data);
        }
Example #8
0
        public JsonResult CreateRoom(PlayerRoom room)
        {
            bool flag = roomList.Add(new PlayerRoom {
                TotalLimit = room.TotalLimit,
                Name       = room.Name,
                PlayerList = new List <Player>(),
            });

            if (flag)
            {
                var query       = roomList.FindAll(x => string.Equals(x.Name, room.Name));
                var queryPlayer = playerList.FindAll(x => string.Equals(x.ConnectionId, Context.ConnectionId));
                if (query != null && query.Count > 0)
                {
                    if (queryPlayer != null && queryPlayer.Count > 0)
                    {
                        queryPlayer.FirstOrDefault().RoomName = room.Name;
                        query.FirstOrDefault().PlayerList.Add(queryPlayer.FirstOrDefault());
                        Groups.Add(Context.ConnectionId, room.Name);
                        CurrentRoomList();
                        return(new JsonResult {
                            Data = new { result = true, data = JavaScriptObjectParser.Parse(roomList) }
                        });
                    }
                    else
                    {
                        return(new JsonResult {
                            Data = new { result = false }
                        });
                    }
                }
                else
                {
                    return(new JsonResult {
                        Data = new { result = false }
                    });
                }
            }
            else
            {
                return(new JsonResult {
                    Data = new { result = false }
                });
            }
        }
Example #9
0
        // TODO: Error messages

        public void HandleMessage(IncomingMessage message, ClientHandler clientHandler)
        {
            // TODO: Start game
            Player receiver = clientHandler.GetPlayer();

            if (receiver.State == PlayerState.Lobby)
            {
                string challengerUsername = message.Document.Attribute("name").Value;

                if (PlayerRoom.HasPlayer(challengerUsername))
                {
                    Player challenger = PlayerRoom.GetPlayer(challengerUsername);
                    if (challenger.HasChallengedPlayer(receiver))
                    {
                        // TODO: Challenger challenged receiver.
                    }
                }
            }
        }
Example #10
0
    // Use this for initialization
    public override void Start()
    {
        base.Start();
        FindObjectOfType <Instruction>().Police();
        state = new PoliceArriving(this, new ChaseRoom1(state));

        roomOfPlayer   = FindObjectOfType <PlayerRoom>();
        goToPostitions = new Transform[roomOfPlayer.Rooms.Length];
        for (int i = 0; i < roomOfPlayer.Rooms.Length; i++)
        {
            //Child of 1 and 3 has more accurate position, bit hacky
            if (i != 1 && i != 3)
            {
                goToPostitions[i] = roomOfPlayer.Rooms[i].transform;
            }
            else
            {
                goToPostitions[i] = roomOfPlayer.Rooms[i].transform.GetChild(0);
            }
        }
    }
        public async Task <ActionResult <PlayerRoom> > PostPlayerRoom(PlayerRoom playerRoom)
        {
            _context.PlayerRoom.Add(playerRoom);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (PlayerRoomExists(playerRoom.PlayerId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetPlayerRoom", new { id = playerRoom.PlayerId }, playerRoom));
        }
Example #12
0
        public void HandleMessage(IncomingMessage message, ClientHandler clientHandler)
        {
            var name    = message.Document?.Attribute("name")?.Value;
            var version = message.Document?.Attribute("version")?.Value;
            var sso     = message.Document?.Attribute("hash")?.Value;

            if (name == null || version == null || sso == null)
            {
                clientHandler.Disconnect("Invalid MessageEventAuth received.");
                return;
            }

            if (!sso.Equals(Hash.Md5(Program.Config.Salt + name)))
            {
                clientHandler.Disconnect($"SSO mismatch, received '{sso}', expected '{Hash.Md5(Program.Config.Salt + name)}'.");
                return;
            }

            if (PlayerRoom.HasPlayer(name))
            {
                clientHandler.Disconnect("Username already in use.");
                return;
            }

            if (!version.Equals(Constants.Version))
            {
                clientHandler.Disconnect($"Version mismatch, received '{version}', expected '{Constants.Version}'.");
                return;
            }

            Logger.Info($"[{name}] has connected to the server.");

            clientHandler.Username = PlayerRoom.AddPlayer(clientHandler, name, sso, PlayerStatus.Available).Username;
            clientHandler.SendMessage(new[]
            {
                PacketHandler.GetComposer <ComposerConfig>().Compose(),
                PacketHandler.GetComposer <ComposerUserList>().Compose(),
                // PacketHandler.GetComposer<ComposerWarning>().Compose("AeonLucid", "Welkom op de pinguin bomberman private server! Op het moment in Alpha-modus.\n\nDit bericht verdwijnt vanzelf.")
            });
        }
Example #13
0
        // TODO: Error messages

        public void HandleMessage(IncomingMessage message, ClientHandler clientHandler)
        {
            var receiver = clientHandler.GetPlayer();

            if (receiver.State == PlayerState.Lobby ||
                receiver.State == PlayerState.GameEnded)
            {
                var challengerUsername = message.Document?.Attribute("name")?.Value;
                if (challengerUsername != null && PlayerRoom.HasPlayer(challengerUsername))
                {
                    var opponent = PlayerRoom.GetPlayer(challengerUsername);
                    if (opponent.HasChallengedPlayer(receiver))
                    {
                        var game = new PlayerGame(receiver, opponent);

                        receiver.StartGame(game);
                        opponent.StartGame(game);

                        game.Start();
                    }
                }
            }
        }
Example #14
0
        private void ReceiveDataCallback(IAsyncResult ar)
        {
            if (ClientSocket == null || !ClientSocket.Connected || Disposing)
            {
                return;
            }

            try
            {
                var bytesReceived = ClientSocket.EndReceive(ar);
                if (bytesReceived == 0)
                {
                    Logger.Info($"[{Username ?? "Anonymous"}] has disconnected from the server.");

                    if (Username != null)
                    {
                        PlayerRoom.RemovePlayer(Username);
                    }

                    Disconnect();
                    return;
                }

                var packetBytes = new byte[bytesReceived];
                Buffer.BlockCopy(SocketBuffer, 0, packetBytes, 0, bytesReceived);

                var packetString = Encoding.ASCII.GetString(packetBytes);

                packetString = packetString.Substring(0, packetString.Length - 1); // TODO: Make sure entire packet is here /0
                packetString = Constants.PacketFix.Replace(packetString, match =>  // Fix packet starting with numbers
                {
                    var replacement = Constants.PacketFixMap[match.Groups["number"].Value];

                    return($"<{replacement} ");
                });

                try
                {
                    var packetXml = XElement.Parse(packetString);
                    if (packetXml.Name.LocalName.Equals("policy-file-request"))
                    {
                        Logger.Debug("Received policy request");

                        ClientSocket.Send(Encoding.ASCII.GetBytes(CrossDomainPolicy.GetPolicy()));
                    }
                    else
                    {
                        PacketHandler.HandleIncomingMessage(new IncomingMessage(packetXml), this);
                    }
                }
                catch (XmlException exception)
                {
                    Logger.Error(exception, $"[{Username ?? "Anonymous"}] Invalid xml was received: '{packetString}'.");
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, $"[{Username ?? "Anonymous"}] Client generated an exception.");
            }
            finally
            {
                ReceiveData();
            }
        }