예제 #1
0
        public virtual void HandleMEmote(GhostNetConnection con, GhostNetFrame frame)
        {
            ChunkMEmote emote = frame;

            // Logger.Log(LogLevel.Info, "ghostnet-s", $"#{frame.HHead.PlayerID} emote: {frame.MEmote.Value}");

            emote.Value = emote.Value.Trim();
            if (emote.Value.Length > GhostNetModule.Settings.ServerMaxEmoteValueLength)
            {
                emote.Value = emote.Value.Substring(0, GhostNetModule.Settings.ServerMaxEmoteValueLength);
            }

            if (GhostNetEmote.IsText(emote.Value))
            {
                frame.Add(CreateMChat(frame, emote.Value, color: GhostNetModule.Settings.ServerColorEmote));
            }

            frame.PropagateM = true;
        }
예제 #2
0
        public void RunKevinballMatch()
        {
            if (KevinballPlayerIDs.Count < 2)
            {
                return;
            }

            if (ActiveKevinballMatch)
            {
                return;
            }

            uint player1 = KevinballP1;
            uint player2 = KevinballP2;

            ActiveKevinballMatch = true;

            if (!PlayerMap.ContainsKey(player1) || !PlayerMap.ContainsKey(player2) || !KevinballScores.ContainsKey(player1) || !KevinballScores.ContainsKey(player2))
            {
                return;
            }

            string p1Name  = PlayerMap[player1].Name;
            string p2Name  = PlayerMap[player2].Name;
            string p1Score = KevinballScores[player1].X.ToString() + " - " + KevinballScores[player1].Y.ToString();
            string p2Score = KevinballScores[player2].X.ToString() + " - " + KevinballScores[player2].Y.ToString();
            //BroadcastMChat(new GhostNetFrame
            //{
            //    HHead = new ChunkHHead
            //    {
            //        PlayerID = uint.MaxValue;
            //},
            //}, "Starting Kevinball!" + p1Name + " [" + p1Score + "] vs. " + p2Name + " [" + p2Score + "]");

            string finalString = "Starting Kevinball! " + p1Name + " [" + p1Score + "] vs. " + p2Name + " [" + p2Score + "]";

            BroadcastMChat(new GhostNetFrame
            {
                HHead = new ChunkHHead
                {
                    PlayerID = uint.MaxValue
                }
            }, finalString);

            GhostNetFrame frame = new GhostNetFrame
            {
                HHead = new ChunkHHead
                {
                    PlayerID = uint.MaxValue
                }
            };

            ChunkMKevinballStart chunk = new ChunkMKevinballStart
            {
                Player1 = player1,
                Player2 = player2
            };

            frame.Add(chunk);
            PropagateM(frame);


            //Send Kevinball start chunk with both player ids
        }
예제 #3
0
        public virtual void HandleULoadedKevinball(GhostNetConnection con, GhostNetFrame frame)
        {
            ChunkULoadedKevinball press = frame;

            ChunkMPlayer otherPlayer;

            if (!PlayerMap.TryGetValue(press.With, out otherPlayer) || otherPlayer == null ||
                frame.MPlayer.SID != otherPlayer.SID ||
                frame.MPlayer.Mode != otherPlayer.Mode
                )
            {
                // Player not in the same room.
                return;
            }

            if (!KevinballPlayerIDs.Contains(press.With))
            {
                KevinballPlayerIDs.Add(press.With);
                KevinballQueue.Add(press.With);

                // TESTING
                //KevinballPlayerIDs.Add(press.With);
                //KevinballQueue.Add(press.With);
            }

            if (!KevinballScores.ContainsKey(press.With))
            {
                KevinballScores.Add(press.With, new Vector2(0, 0));
            }

            if (ActiveKevinballMatch)
            {
                return;
            }

            if (KevinballPlayerIDs.Count - SpectatingPlayers.Count >= 2)
            {
                if (FirstKevinballMatch)
                {
                    GhostNetFrame shuffle_frame = new GhostNetFrame
                    {
                        HHead = new ChunkHHead
                        {
                            PlayerID = uint.MaxValue
                        }
                    };

                    uint randomLevel = PickRandomLevel();
                    CurrentKevinballLevel = randomLevel;

                    ChunkMKevinballShuffle chunk = new ChunkMKevinballShuffle
                    {
                        NextLevel = randomLevel
                    };

                    shuffle_frame.Add(chunk);
                    PropagateM(shuffle_frame);
                    FirstKevinballMatch = false;
                }

                StartKevinball(con, frame);
            }
        }
예제 #4
0
        public void EndKevinballMatch(uint winner, uint loser, uint wintype)
        {
            ActiveKevinballMatch    = false;
            LastKevinballWinner     = winner;
            LastKevinballLoser      = loser;
            KevinballScores[winner] = new Vector2(KevinballScores[winner].X + 1, KevinballScores[winner].Y);
            KevinballScores[loser]  = new Vector2(KevinballScores[loser].X, KevinballScores[loser].Y + 1);

            if (!PlayerMap.ContainsKey(winner))
            {
                return;
            }

            string finalString = PlayerMap[winner].Name + " wins!";

            if (wintype == GhostNetClient.KevinballWin)
            {
                finalString = finalString + " GOOOOAAAAALLLL!!";
            }
            else if (wintype == GhostNetClient.CoinWin)
            {
                finalString = finalString + " Coin victory!";
            }
            else if (wintype == GhostNetClient.DeathWin)
            {
                finalString = finalString + " Survival victory!";
            }

            BroadcastMChat(new GhostNetFrame
            {
                HHead = new ChunkHHead
                {
                    PlayerID = uint.MaxValue
                }
            }, finalString);

            GhostNetFrame frame = new GhostNetFrame
            {
                HHead = new ChunkHHead
                {
                    PlayerID = uint.MaxValue
                }
            };

            bool shouldShuffle = false;

            if (ShuffleMode > 0)
            {
                foreach (KeyValuePair <uint, Vector2> kvp in KevinballScores)
                {
                    if (kvp.Value.X >= ShuffleMode)
                    {
                        shouldShuffle = true;
                        string name = PlayerMap[kvp.Key].Name;
                        string str  = name + " wins the map! Shuffling maps...";
                        BroadcastMChat(new GhostNetFrame
                        {
                            HHead = new ChunkHHead
                            {
                                PlayerID = uint.MaxValue
                            }
                        }, str);
                    }
                }

                if (shouldShuffle == true)
                {
                    CurrentKevinballLevel = PickRandomLevel();
                    justShuffled          = true;
                }
            }

            if (shouldShuffle)
            {
                List <uint> keys = KevinballScores.Keys.ToList();
                foreach (uint key in keys)
                {
                    KevinballScores[key] = new Vector2(0, 0);
                }
            }

            ChunkMKevinballEnd chunk = new ChunkMKevinballEnd
            {
                Winner    = winner,
                Wintype   = wintype,
                NextLevel = CurrentKevinballLevel
            };

            frame.Add(chunk);
            PropagateM(frame);
        }