@@ -12,92 +12,20 @@ public static class InstanceMapper
1212
1313 public static ServerSnapshot CreateSnapshot (
1414 theInstance server ,
15- Dictionary < int , playerObject > playerList ,
15+ playerInstance playerList ,
1616 chatInstance chat ,
1717 banInstance bans ,
1818 mapInstance maps )
1919 {
2020 return new ServerSnapshot
2121 {
2222 ServerData = server ,
23- Players = MapPlayerInstance ( playerList ) ,
23+ Players = playerList ,
2424 Chat = chat ,
25- Bans = MapBanInstance ( bans ) ,
25+ Bans = bans ,
2626 Maps = maps ,
2727 SnapshotTime = DateTime . UtcNow
2828 } ;
2929 }
3030
31- private static PlayerInstanceDTO MapPlayerInstance ( Dictionary < int , playerObject > playerList )
32- {
33- var players = playerList . ToDictionary (
34- kvp => kvp . Key ,
35- kvp => new PlayerDTO
36- {
37- Slot = kvp . Value . PlayerSlot ,
38- Name = DecodePlayerName ( kvp . Value . PlayerNameBase64 ) ,
39- IPAddress = kvp . Value . PlayerIPAddress ,
40- Team = kvp . Value . PlayerTeam ,
41- Ping = kvp . Value . PlayerPing ,
42- Kills = kvp . Value . stat_Kills ,
43- Deaths = kvp . Value . stat_Deaths
44- }
45- ) ;
46-
47- return new PlayerInstanceDTO { Players = players } ;
48- }
49-
50- private static ChatInstanceDTO MapChatInstance ( chatInstance chat )
51- {
52- return new ChatInstanceDTO
53- {
54- RecentMessages = chat . ChatLog . TakeLast ( 100 ) . Select ( log => new ChatMessageDTO
55- {
56- Timestamp = log . MessageTimeStamp ,
57- PlayerName = log . PlayerName ,
58- Message = log . MessageText ,
59- Team = GetTeamName ( log . MessageType2 )
60- } ) . ToList ( ) ,
61- SlapMessages = chat . SlapMessages . Select ( s =>
62- new SlapMessageDTO ( s . SlapMessageId , s . SlapMessageText ) ) . ToList ( )
63- } ;
64- }
65-
66- private static BanInstanceDTO MapBanInstance ( banInstance bans )
67- {
68- return new BanInstanceDTO
69- {
70- BannedNames = bans . BannedPlayerNames . Select ( b =>
71- new BannedNameDTO ( b . RecordID , b . PlayerName , b . Date , b . RecordType . ToString ( ) ) ) . ToList ( ) ,
72- BannedIPs = bans . BannedPlayerIPs . Select ( b =>
73- new BannedIPDTO ( b . RecordID , b . PlayerIP . ToString ( ) , b . SubnetMask , b . Date , b . RecordType . ToString ( ) ) ) . ToList ( ) ,
74- WhitelistedNames = bans . WhitelistedNames . Select ( w =>
75- new WhitelistedNameDTO ( w . RecordID , w . PlayerName ) ) . ToList ( )
76- } ;
77- }
78-
79- private static string DecodePlayerName ( string ? base64 )
80- {
81- if ( string . IsNullOrEmpty ( base64 ) ) return "Unknown" ;
82- try
83- {
84- byte [ ] bytes = Convert . FromBase64String ( base64 ) ;
85- return Encoding . GetEncoding ( "Windows-1252" ) . GetString ( bytes ) ;
86- }
87- catch
88- {
89- return "Unknown" ;
90- }
91- }
92-
93- private static string GetTeamName ( int messageType2 )
94- {
95- return messageType2 switch
96- {
97- 1 => "Blue" ,
98- 2 => "Red" ,
99- 3 => "Host" ,
100- _ => "All"
101- } ;
102- }
10331}
0 commit comments