Пример #1
0
 public Player(WebSocket ws, String username, String uniqueId)
 {
     // TODO: Actually write code that'll connect to a DB to see if we can pull rating information.
     this.ws = ws;
     this.username = username;
     this.uniqueId = uniqueId;
     this.rating = 0;
     this.currentMatch = null;
 }
Пример #2
0
 public void ReportMatchDone(Match match) {
     try
     {
         // remove dictionary associations
         // theoretically, after removing dictionary associations, this "match" is the final reference to the match.
         idToPlayerDictionary.Remove(match.attacker.getUniqueId());
         idToPlayerDictionary.Remove(match.defender.getUniqueId());
         wsToIdDictionary.Remove(match.attacker.getSocket());
         wsToIdDictionary.Remove(match.defender.getSocket());
     }
     catch (Exception aex)
     {
         Console.WriteLine("Error Cleaning Up Match: " + aex.GetBaseException().Message);
     }
     // match.attacker.getSocket().Dispose();
 }
Пример #3
0
        public void HandleMatchQueue(WebSocket ws,  Dictionary<string, dynamic> msgDict)
        {
            String socketId = msgDict["uniqueId"];
            // Check if ID is not already in Queue.
            if (!attackerQueue.Contains(socketId) && !defenderQueue.Contains(socketId))
            {
                // Check that the ws isn't in a match already
                if (!wsToIdDictionary.ContainsKey(ws))
                {
                    // Queue the websocket, wait for friend.
                    if (msgDict["msgType"].StartsWith("LogInRequest"))
                    {
                        Player p = new Player(ws, msgDict["username"], socketId);
                        wsToIdDictionary.Add(ws, socketId);
                        idToPlayerDictionary.Add(socketId, p);

                        if (msgDict["role"].ToLower() == "attacker")
                        {
                            Console.WriteLine("An attacker joined the game: " + ws.RemoteEndpoint);
                            if (defenderQueue.Count != 0)
                            {
                                String defenderId = defenderQueue.Dequeue();
                                Player defender = idToPlayerDictionary[defenderId];

                                Match newMatch = new Match(p, defender, this);
                            }
                            else
                            {
                                attackerQueue.Enqueue(socketId);
                            }
                        }
                        else if (msgDict["role"].ToLower() == "defender")
                        {
                            Console.WriteLine("A defender joined the game: " + ws.RemoteEndpoint);
                            if (attackerQueue.Count != 0)
                            {
                                String attackerId = attackerQueue.Dequeue();
                                Player attacker = idToPlayerDictionary[attackerId];

                                Match newMatch = new Match(attacker, p, this);
                            }
                            else
                            {
                                defenderQueue.Enqueue(socketId);
                            }
                        }
                    }
                }
            }
            else
            {
                ws.WriteString("Please wait for a match to start.");
            }
        }