public DataPacket createDataPacket(string newName, int newScore, Dictionary<string, int> newHighscoresList) { DataPacket packet = new DataPacket(); packet.name = newName; packet.score = newScore; packet.highscores = newHighscoresList; return packet; }
public void addHighscore(DataPacket newHighscore) { DataPacket highscore = newHighscore; ServerView.writeToConsole("Received new score (Name: "+highscore.name+", score: "+highscore.score+")"); highscores = highscores.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value); if (highscore.score > highscores.Values.Last() || highscores.Count < 6) { foreach(KeyValuePair<string, int> pair in highscores) { if(pair.Key == highscore.name && pair.Value < highscore.score) { highscores.Remove(pair.Key); break; } } } highscores.Add(highscore.name, highscore.score); highscores = highscores.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value); if (highscores.Count > 5) highscores.Remove(highscores.Keys.Last()); finalizeData(); }
public void addHighscore(DataPacket highscore) { serverModel.addHighscore(highscore); }
public void handleDataPacket(DataPacket data) { if (data.name == "updateHighscores") gameLogic.setHighscores(data); }
public void sendToServer(DataPacket data) { try { formatter.Serialize(sslStream, data); } catch { Console.WriteLine("Could not send data to server."); } }
public void setHighscores(DataPacket data) { highscores = data.highscores; mainForm.setHighScoreListInfoDictionary(highscores); }
public void sendHighscore(DataPacket highscore) { networkClient.sendToServer(highscore); }
public void saveHighScoreDictionary(DataPacket highscore) { highscores = highscores.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value); if (highscore.score > highscores.Values.Last() || highscores.Count <= 4) { if (highscores.Count >= 4) highscores.Remove(highscores.Keys.Last()); highscores.Add(highscore.name, highscore.score); } highscores = highscores.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value); }
public void handleDataPacket(DataPacket data) { //if (data.name == "exit") disconnect(); serverControl.addHighscore(data); }
public void sendDataToClient(DataPacket data) { try { formatter.Serialize(clientStream, data); } catch { } }