Example #1
0
        private static void HandleOnRequestMatchDataPackage(RequestMatchDataPackage package)
        {
            var match = GetMatchByUid(package.MatchUid);
            DrawingHammerClientData client = (DrawingHammerClientData)_server.GetClientFromClientList(package.SenderUid);

            client.EnqueueDataForWrite(new MatchDataPackage(new MatchData(match), Router.ServerWildcard, client.Uid));
        }
Example #2
0
        private static void HandleOnJoinMatchPackage(JoinMatchPackage package)
        {
            Match match = GetMatchByUid(package.MatchUid);
            DrawingHammerClientData client = (DrawingHammerClientData)_server.GetClientFromClientList(package.SenderUid);

            if (match.IsFinished)
            {
                client.EnqueueDataForWrite(new MatchJoinFailedPackage("Match is already finished!", package.SenderUid, Router.ServerWildcard));
            }
            else if (match.Players.Count < match.MaxPlayers)
            {
                Player player = new Player(client.User.Id, client.Uid, client.User.Username, 0);
                match.Players.Add(player);

                _server.Router.DistributePackage(new PlayerJoinedMatchPackage(
                                                     match.MatchUid,
                                                     player,
                                                     Router.ServerWildcard,
                                                     Router.AllAuthenticatedWildCard));

                if (match.IsSubRoundRunning)
                {
                    //Notify player that a round already started
                    Log.Debug("Match is currently running - send subround started again!");
                    _server.Router.DistributePackage(new SubRoundStartedPackage(Router.ServerWildcard, package.SenderUid));
                }

                if (match.Players.Count > 1 && !match.IsRunning)
                {
                    match.StartMatch();
                }
            }
            else
            {
                client.EnqueueDataForWrite(new MatchJoinFailedPackage("Maximum player count reached!", package.SenderUid, Router.ServerWildcard));
            }
        }