public void LogPlayer(string ip, string name) { Load(); System.Diagnostics.Debug.Assert(!name.Contains(',')); List <string> uniquenames; LoggedPlayer match = loggedPlayers.Find(bp => bp.IP == ip); if (match != null) { if (match.UniqueNames.Any(bp => bp == name.ToLowerInvariant())) { return; } uniquenames = match.UniqueNames; uniquenames.Add(name.ToLowerInvariant()); //uniquenames.Sort(); loggedPlayers.Remove(match); } else { uniquenames = new List <string>(); uniquenames.Add(name.ToLowerInvariant()); } loggedPlayers.Add(new LoggedPlayer(ip, uniquenames)); //loggedPlayers.Sort(); loggedPlayers = loggedPlayers.OrderBy(x => x.ToString()).ToList(); Save(); }
public string ListPrevious(string ip, string joinname, Boolean includeip, Boolean statenames, Boolean IsJoinMessage) { string returnmessage = ""; LoggedPlayer match = loggedPlayers.Find(bp => bp.IP == ip); DisconnectedCharacter ReconnectedClient = null; KickedClient kickedclient = null; if (GameMain.NilMod.DisconnectedCharacters.Count > 0) { ReconnectedClient = GameMain.NilMod.DisconnectedCharacters.Find(dc => dc.IPAddress == ip && dc.clientname == joinname); } if (GameMain.NilMod.KickedClients.Count > 0) { kickedclient = GameMain.NilMod.KickedClients.Find(dc => dc.IPAddress == ip && dc.clientname == joinname); } if (kickedclient != null) { if (GameMain.NilMod.ClearKickStateNameOnRejoin) { GameMain.NilMod.KickedClients.Remove(kickedclient); } else { kickedclient.ExpireTimer += GameMain.NilMod.KickStateNameTimerIncreaseOnRejoin; if (kickedclient.ExpireTimer > GameMain.NilMod.KickMaxStateNameTimer) { kickedclient.ExpireTimer = GameMain.NilMod.KickMaxStateNameTimer; } } } if (match == null && ReconnectedClient == null && kickedclient == null) { if (includeip) { returnmessage = "New Player " + joinname + " (" + ip + ") has joined."; } else { returnmessage = "New Player " + joinname + " has joined."; } } else { if (IsJoinMessage) { if (includeip) { if (kickedclient != null) { returnmessage = "Kicked Player " + joinname + " (" + kickedclient.clientname + ") (" + ip + ") has rejoined"; } else if (ReconnectedClient != null) { returnmessage = joinname + " (" + ip + ") has reconnected"; } else { returnmessage = joinname + " (" + ip + ") has joined"; } } else { if (kickedclient != null) { returnmessage = "Kicked Player " + joinname + " (" + kickedclient.clientname + ") has rejoined"; } else if (ReconnectedClient != null) { returnmessage = joinname + " has reconnected"; } else { returnmessage = joinname + " has joined"; } } } if (PlayerLogStateNames | statenames) { if (!PlayerLogStateFirstJoinedNames && !PlayerLogStateLastJoinedNames) { PlayerLogStateLastJoinedNames = true; } if (match.UniqueNames.Count() > 1) { int ListedNames = 0; returnmessage += " - Previously ("; if (PlayerLogStateFirstJoinedNames) { //Loop from the start of the names, for the first recorded. for (int i = 0; i < match.UniqueNames.Count() && ListedNames < (PlayerLogStateLastJoinedNames ? 2 : 4); i++) { if (match.UniqueNames[i] != joinname.ToLowerInvariant()) { if (ListedNames != 0) { returnmessage += ", "; } returnmessage += match.UniqueNames[i]; ListedNames += 1; } } } if (PlayerLogStateLastJoinedNames) { //Loop from the end of the names, do not include the already declared by previous one. for (int i = match.UniqueNames.Count() - 1; i > ListedNames && ListedNames <= 4; i--) { if (match.UniqueNames[i] != joinname.ToLowerInvariant()) { if (ListedNames != 0) { returnmessage += ", "; } returnmessage += match.UniqueNames[i]; ListedNames += 1; } } } returnmessage += ")"; } } returnmessage += "."; } return(returnmessage); }