Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 00147 00148 00149 00150 00151 00152 00153 00154 00155 00156 00157 00158 00159 00160 00161 00162 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 00173 00174 00175 00176 00177 00178 00179 00180 00181 00182 00183 00184 00185 00186 00187 00188 00189 00190 00191 00192 00193 00194 00195 00196 00197 00198 00199 00200 00201 00202 00203 00204 00205 00206 00207 00208 00209 00210 00211 00212 00213 00214 00215 00216 00217 00218 00219 00220 00221 00222 00223 00224 00225 00226 00227 00228 00229 00230 00231 00232 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 00257 00258 00259 00260 00261 00262 00263 00264 00265 00266 00267 00268 00269 00270 00271 00272 00273 00274 00275 00276 00277 00278 00279 00280 00281 00282 00283 00284 00285 00286 00287 00288 00289 00290 00291 00292 00293 00294 00295 00296 00297 00298 00299 00300 00301 00302 00303 00304 00305 00306 00307 00308 00309 00310 00311 00312 00313 00314 00315 00316 00317 00318 00319 00320 00321 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 00335 00336 00337 00338 00339 00340 00341 00342 00343 00344 00345 00346 00347 00348 00349 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 00377 00378 00379 00380 00381 00382 00383 00384 00385 00386 00387 00388 00389 00390 00391 00392 00393 00394 00395 00396 00397 00398 00399 00400 00401 00402 00403 00404 00405 00406 00407 00408 00409 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 00429 00430 00431 00432 00433 00434 00435 00436 00437 00438 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 00451 00452 00453 00454 00455 00456 00457 00458 00459 00460 00461 00462 00463 00464 00465 00466 00467 00468 00469 00470 00471 00472 00473 |
//============================================================================== // Created on: 08/29/2003 // UnrealPlayerChatManager is responsible for tracking each player's chat preferences and restrictions. // When a client joins the game, a new UnrealPlayerChatManager object is spawned for that player, and replicated // to the client. When the UnrealPlayerChatManager object arrives on the client, it requests a list of player hashes // for all players currently connected to the server. // The hashes received from the server are matched against the local client's stored restrictions. When a match is // found, UnrealPlayerChatManager updates the server's copy of the tracking information with the client's restriction. // // Thereafter, when the client's copy of the UnrealPlayerChatManager object is notified that a new client has // connected, it requests the hash information for that player in order to match it against the client's stored // restrictions. // // Written by Ron Prestenback // © 2003, Epic Games, Inc. All Rights Reserved //============================================================================== class UnrealPlayerChatManager extends PlayerChatManager config(ChatRestriction); const NOTEXT = 1; const NOSPEECH = 2; const NOVOICE = 4; const BANNED = 8; struct StoredChatBan { var string PlayerHash; var byte Restriction; }; struct ChatBan { var int PlayerID; var string PlayerHash; var string PlayerAddress; var byte PlayerVoiceMask; var byte Restriction; // 1 - Text, 2 - Speech, 4 - Voice, 8 - Banned from private chat }; // Restricted player hashes. var globalconfig protected array<StoredChatBan> StoredChatRestrictions; var protected array<ChatBan> ChatRestrictions; simulated function ChatDebug() { local int i; for ( i = 0; i < StoredChatRestrictions.Length; i++ ) { log(" StoredChatRestrictions["$i$"] Hash:"$StoredChatRestrictions[i].PlayerHash@"Restriction:"$StoredChatRestrictions[i].Restriction); } for ( i = 0; i < ChatRestrictions.Length; i++ ) { LogChatRestriction(i); } } simulated function LogChatRestriction(int i) { log(" ChatRestrictions["$i$"] PlayerID:"$ChatRestrictions[i].PlayerID@ "Hash:"$ChatRestrictions[i].PlayerHash@ "Address:"$ChatRestrictions[i].PlayerAddress@ "Mask:"$ChatRestrictions[i].PlayerVoiceMask@ "Restriction:"$ChatRestrictions[i].Restriction); } // Called from TrackNewPlayer when we receive a new player's information - check to see if we placed a restriction on // this player during a previous match simulated protected function bool LoadChatBan(string PlayerHash, out byte OutRestriction) { local int i; for ( i = 0; i < StoredChatRestrictions.Length; i++ ) { if ( StoredChatRestrictions[i].PlayerHash == PlayerHash ) { OutRestriction = StoredChatRestrictions[i].Restriction; return true; } } return false; } // Save the PlayerHash and Restriction to persistent array simulated protected function StoreChatBan(string PlayerHash, byte Restriction) { local int i; // First, determine if this player is already in our list - if so, replace the restriction with the specified one for ( i = 0; i < StoredChatRestrictions.Length; i++ ) { if ( StoredChatRestrictions[i].PlayerHash == PlayerHash ) break; } if ( i == StoredChatRestrictions.Length ) { // If the restriction is 0, stop here - no restriction if ( Restriction == 0 ) return; StoredChatRestrictions.Length = i + 1; } else if ( Restriction == 0 ) { StoredChatRestrictions.Remove(i,1); return; } log("StoreChatBan PlayerHash:"$PlayerHash@"Restriction:"$Restriction,'ChatManager'); StoredChatRestrictions[i].PlayerHash = PlayerHash; StoredChatRestrictions[i].Restriction = Restriction; } // Called from xPlayer.ServerRequestBanInfo - used to track player hashes on the client simulated function ReceiveBanInfo(string S) { local array<string> Arr; local int PlayerID; local string PlayerHash, PlayerAddress; log(Name@"ReceiveBanInfo S:"$S,'ChatManager'); Split(S, Chr(27), Arr); if ( Arr.Length < 3 ) { log("Error receiving ban info Arr.Length:"$Arr.Length@S,'ChatManager'); return; } PlayerID = int(Arr[0]); PlayerHash = Arr[1]; PlayerAddress = Arr[2]; TrackNewPlayer(PlayerID, PlayerHash, PlayerAddress); } // Called when we've received a new playerhash from ReceiveBanInfo - simulated function TrackNewPlayer(int PlayerID, string PlayerHash, string PlayerAddress) { local int i; local PlayerReplicationInfo PRI; local byte NewRestriction; if ( PlayerOwner == None ) { log(Name@"Couldn't update server tracking - No PlayerOwner!",'ChatManager'); return; } log(Name@"___________________TrackNewPlayer PlayerID:"$PlayerID@"PlayerHash:"$PlayerHash@"PlayerAddress:"$PlayerAddress,'ChatManager'); // First, check if we're already tracking this player for ( i = 0; i < ChatRestrictions.Length; i++ ) if ( ChatRestrictions[i].PlayerID == PlayerID ) break; if ( i == ChatRestrictions.Length ) ChatRestrictions.Length = ChatRestrictions.Length + 1; // Next, check if we've got this player's hash in our list of stored bans...if so, notify the server about our preference if ( Role < ROLE_Authority && LoadChatBan(PlayerHash, NewRestriction) ) PlayerOwner.ServerChatRestriction(PlayerID, NewRestriction); else if ( Level.NetMode == NM_ListenServer && PlayerOwner == Level.GetLocalPlayerController() ) LoadChatBan(PlayerHash, NewRestriction); // Now, add this player to the instance tracking ChatRestrictions[i].PlayerID = PlayerID; ChatRestrictions[i].PlayerHash = PlayerHash; ChatRestrictions[i].PlayerAddress = PlayerAddress; ChatRestrictions[i].Restriction = NewRestriction; // Finally, add this player's voice mask to the tracking info (only happens on server). // VoiceID is used to determine which players are in which channels PRI = PlayerOwner.GameReplicationInfo.FindPlayerByID(PlayerID); if ( PRI != None ) ChatRestrictions[i].PlayerVoiceMask = PRI.VoiceID; // else log(Name@"TrackNewPlayer No PRI so couldn't update VoiceID for ChatRestrictions["$i$"]",'ChatManager'); } simulated function UnTrackPlayer(int PlayerID) { local int i; log("Untrack player:"$PlayerID,'ChatManager'); // Remove this player from the ban tracking system for ( i = 0; i < ChatRestrictions.Length; i++ ) { if ( ChatRestrictions[i].PlayerID == PlayerID ) { ChatRestrictions.Remove(i,1); return; } } log("Untrack player couldn't find restriction for PlayerID:"$PlayerID,'ChatManager'); } // Returns whether we should receive text messages from Sender function bool AcceptText( PlayerReplicationInfo Sender, out string Msg, optional name Type ) { local int i; if ( Sender == None ) return Super.AcceptText(Sender, Msg, Type); i = GetIDIndex(Sender.PlayerID); if ( !IsValid(i) ) return true; log(Name@"Owner:"$PlayerOwner.PlayerReplicationInfo.PlayerName@"Restriction for Index "$i$":"$ChatRestrictions[i].Restriction,'ChatManager'); return !bool(ChatRestrictions[i].Restriction & NOTEXT); } // Returns whether we should receive Speech messages from Sender function bool AcceptSpeech(PlayerReplicationInfo SenderPRI) { local int i; if ( SenderPRI == None ) return Super.AcceptSpeech(SenderPRI); i = GetIDIndex(SenderPRI.PlayerID); if ( !IsValid(i) ) return true; return !bool(ChatRestrictions[i].Restriction & NOSPEECH); } // Returns whether we should accept voice messages from sender event bool AcceptVoice(PlayerReplicationInfo SenderPRI) { local int i; if ( SenderPRI == None ) return Super.AcceptVoice(SenderPRI); i = GetIDIndex(SenderPRI.PlayerID); if ( !IsValid(i) ) return true; return !bool(ChatRestrictions[i].Restriction & NOVOICE); } function bool IsBanned(PlayerReplicationInfo PRI) { local int i; local string PlayerHash; PlayerHash = PlayerController(PRI.Owner).GetPlayerIDHash(); log(Name@"IsBanned() PRI:"$PRI.Name,'ChatManager'); for (i = 0; i < ChatRestrictions.Length; i++) { if (ChatRestrictions[i].PlayerHash == PlayerHash) { log(Name@"IsBanned() found matching PlayerHash for"@PlayerHash$":"$i@"Restriction:"$ChatRestrictions[i].Restriction,'ChatManager'); return bool(ChatRestrictions[i].Restriction & BANNED); } } return Super.IsBanned(PRI); } // Update the restrictions on chat for a player simulated function bool SetRestriction(string PlayerHash, byte Type) { local int i; i = GetHashIndex(PlayerHash); log(Name@"SetRestriction PlayerHash:"$PlayerHash@"i:"$i@"Type:"$Type,'ChatManager'); if ( !IsValid(i) ) { // If we aren't currently tracking this player, and the restriction is none, don't add the restriction if ( Type == 0 ) return false; i = ChatRestrictions.Length; ChatRestrictions.Length = i + 1; } // If the new restriction is the same as the current restriction, stop here else if ( ChatRestrictions[i].Restriction == Type ) return false; ChatRestrictions[i].Restriction = Type; // If we're the client, copy the restriction to the persistent array if ( IsLocal() ) { StoreChatBan(PlayerHash, Type); SaveConfig(); } return true; } simulated function bool SetRestrictionID(int PlayerID, byte Type) { local string PlayerHash; log(Name@"SetRestrictionID PlayerID:"$PlayerID@"Type:"$Type,'ChatManager'); // Query the player's hash from the tracking system PlayerHash = GetPlayerHash(PlayerID); if ( PlayerHash == "" ) return false; return SetRestriction(PlayerHash, Type); } simulated function bool AddRestriction( string PlayerHash, byte Type ) { return MergeRestriction( GetHashIndex(PlayerHash), Type ); } simulated function bool AddRestrictionID( int PlayerID, byte Type ) { return AddRestriction(GetPlayerHash(PlayerID), Type); } simulated function bool ClearRestriction( string PlayerHash, byte Type ) { return UnMergeRestriction( GetHashIndex(PlayerHash), Type); } simulated function bool ClearRestrictionID( int PlayerID, byte Type ) { return ClearRestriction( GetPlayerHash(PlayerID), Type); } // Used to update a restriction if calling function doesn't know the current restriction of the player // This function cannot be used to _remove_ a restriction - use UnMerge restriction instead simulated function bool MergeRestriction(int Index, byte NewType) { if ( !IsValid(Index) ) return false; // First, clear the bits ChatRestrictions[Index].Restriction = ChatRestrictions[Index].Restriction & ~NewType; // Now, set the bits ChatRestrictions[Index].Restriction = ChatRestrictions[Index].Restriction | NewType; if ( IsLocal() ) { StoreChatBan(ChatRestrictions[Index].PlayerHash, ChatRestrictions[Index].Restriction); SaveConfig(); } return True; } simulated function bool UnMergeRestriction(int Index, byte NewType) { if ( !IsValid(Index) ) return false; if ( !bool(ChatRestrictions[Index].Restriction & NewType) ) return False; ChatRestrictions[Index].Restriction = ChatRestrictions[Index].Restriction & ~NewType; if ( IsLocal() ) { StoreChatBan(ChatRestrictions[Index].PlayerHash, ChatRestrictions[Index].Restriction); SaveConfig(); } return True; } //############################################################################################################### // // // Query functions // simulated function byte GetPlayerRestriction(int PlayerID) { local int i; i = GetIDIndex(PlayerID); if ( !IsValid(i) ) return Super.GetPlayerRestriction(PlayerID); return ChatRestrictions[i].Restriction; } simulated function bool ClientIsBanned(string PlayerHash) { local int i; if ( PlayerHash == "" ) return True; for (i = 0; i < ChatRestrictions.Length; i++) if (ChatRestrictions[i].PlayerHash == PlayerHash) return bool(ChatRestrictions[i].Restriction & BANNED); return Super.ClientIsBanned(PlayerHash); } simulated protected function string GetPlayerHash(int PlayerID) { local int i; if ( PlayerID < 1 ) return ""; for ( i = 0; i < ChatRestrictions.Length; i++ ) { log(Name@"GetPlayerHash Match:"$PlayerID@"Test["$i$"]:"$ChatRestrictions[i].PlayerID); if ( ChatRestrictions[i].PlayerID == PlayerID ) return ChatRestrictions[i].PlayerHash; } return ""; } simulated protected function int GetIDIndex(int PlayerID) { local int i; if ( PlayerID < 1 ) return -1; for ( i = 0; i < ChatRestrictions.Length; i++ ) if ( ChatRestrictions[i].PlayerID == PlayerID ) return i; return -1; } simulated protected function int GetHashIndex(string PlayerHash) { local int i; if ( PlayerHash == "" ) return -1; for ( i = 0; i < ChatRestrictions.Length; i++ ) if ( ChatRestrictions[i].PlayerHash == PlayerHash ) return i; return -1; } simulated protected function bool IsValid(int i) { return i >= 0 && i < ChatRestrictions.Length; } simulated function bool IsLocal() { return Level.NetMode == NM_Client || (Level.NetMode == NM_ListenServer && PlayerOwner != None && PlayerOwner == Level.GetLocalPlayerController()); } simulated function int Count() { return ChatRestrictions.Length; } defaultproperties { } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |