88using System . Collections . Generic ;
99using Rocket . API . Collections ;
1010using Rocket . API ;
11+ using GlobalBan ;
1112
1213namespace PlayerInfoLibrary
1314{
@@ -25,6 +26,7 @@ protected override void Load()
2526 Database = new DatabaseManager ( ) ;
2627 U . Events . OnPlayerConnected += Events_OnPlayerConnected ;
2728 U . Events . OnPlayerDisconnected += Events_OnPlayerDisconnected ;
29+ //U.Events.OnBeforePlayerConnected += Events_OnBeforePlayerConnected;
2830 if ( Instance . Configuration . Instance . KeepaliveInterval <= 0 )
2931 {
3032 Logger . LogWarning ( "Error: Keep alive config option must be above 0." ) ;
@@ -42,28 +44,75 @@ protected override void Load()
4244 Logger . Log ( "There was in issue loading the plugin, please check your config." , ConsoleColor . Red ) ;
4345 }
4446
47+
48+
4549 protected override void Unload ( )
4650 {
4751 U . Events . OnPlayerConnected -= Events_OnPlayerConnected ;
4852 U . Events . OnPlayerDisconnected -= Events_OnPlayerDisconnected ;
53+ //U.Events.OnBeforePlayerConnected -= Events_OnBeforePlayerConnected;
4954
5055 Database . Unload ( ) ;
5156 Database = null ;
5257 }
5358
59+ private void Events_OnBeforePlayerConnected ( UnturnedPlayer player )
60+ {
61+ try
62+ {
63+ if ( player != null )
64+ {
65+ if ( LoginTime . ContainsKey ( player . CSteamID ) )
66+ LoginTime . Remove ( player . CSteamID ) ;
67+ LoginTime . Add ( player . CSteamID , DateTime . Now ) ;
68+ PlayerData pData = Database . QueryById ( player . CSteamID , false ) ;
69+ int totalTime = pData . TotalPlayime ;
70+ DateTime loginTime = PlayerInfoLib . LoginTime [ player . CSteamID ] ;
71+ pData = new PlayerData ( player . CSteamID , player . SteamName , player . CharacterName , player . CSteamID . GetIP ( ) , player . CSteamID . GetHWID ( ) , loginTime , Database . InstanceID , Provider . serverName , Database . InstanceID , loginTime , false , false , totalTime ) ;
72+ Database . SaveToDB ( pData ) ;
73+ // Recheck the ip address in the component, the ip isn't always fully set by the time this event is called.
74+ PlayerInfoLibPComponent pc = player . GetComponent < PlayerInfoLibPComponent > ( ) ;
75+ pc . Start ( pData ) ;
76+ }
77+ }
78+ catch ( Exception ex )
79+ {
80+
81+ }
82+ }
83+
5484 private void Events_OnPlayerConnected ( UnturnedPlayer player )
5585 {
56- if ( LoginTime . ContainsKey ( player . CSteamID ) )
57- LoginTime . Remove ( player . CSteamID ) ;
58- LoginTime . Add ( player . CSteamID , DateTime . Now ) ;
59- PlayerData pData = Database . QueryById ( player . CSteamID , false ) ;
60- int totalTime = pData . TotalPlayime ;
61- DateTime loginTime = PlayerInfoLib . LoginTime [ player . CSteamID ] ;
62- pData = new PlayerData ( player . CSteamID , player . SteamName , player . CharacterName , player . CSteamID . GetIP ( ) , player . CSteamID . GetHWID ( ) , loginTime , Database . InstanceID , Provider . serverName , Database . InstanceID , loginTime , false , false , totalTime ) ;
63- Database . SaveToDB ( pData ) ;
64- // Recheck the ip address in the component, the ip isn't always fully set by the time this event is called.
65- PlayerInfoLibPComponent pc = player . GetComponent < PlayerInfoLibPComponent > ( ) ;
66- pc . Start ( pData ) ;
86+ if ( player != null )
87+ {
88+ if ( LoginTime . ContainsKey ( player . CSteamID ) )
89+ LoginTime . Remove ( player . CSteamID ) ;
90+ LoginTime . Add ( player . CSteamID , DateTime . Now ) ;
91+ PlayerData pData = Database . QueryById ( player . CSteamID , false ) ;
92+ int totalTime = pData . TotalPlayime ;
93+ DateTime loginTime = PlayerInfoLib . LoginTime [ player . CSteamID ] ;
94+ pData = new PlayerData ( player . CSteamID , player . SteamName , player . CharacterName , player . CSteamID . GetIP ( ) , player . CSteamID . GetHWID ( ) , loginTime , Database . InstanceID , Provider . serverName , Database . InstanceID , loginTime , false , false , totalTime ) ;
95+ Database . SaveToDB ( pData ) ;
96+ // Recheck the ip address in the component, the ip isn't always fully set by the time this event is called.
97+ PlayerInfoLibPComponent pc = player . GetComponent < PlayerInfoLibPComponent > ( ) ;
98+ pc . Start ( pData ) ;
99+ }
100+
101+ PlayerInfoLib . ExecuteDependencyCode ( "GlobalBan" , ( IRocketPlugin plugin ) =>
102+ {
103+ if ( GlobalBan . GlobalBan . Instance . State == PluginState . Loaded )
104+ {
105+ if ( GlobalBan . GlobalBan . CheckIfBanned ( player ) )
106+ {
107+ if ( GlobalBan . GlobalBan . Instance . BannedReason . TryGetValue ( player , out string reason ) )
108+ {
109+ Provider . kick ( player . CSteamID , reason ) ;
110+ GlobalBan . GlobalBan . Instance . BannedReason . Remove ( player ) ;
111+
112+ }
113+ }
114+ }
115+ } ) ;
67116 }
68117
69118 private void Events_OnPlayerDisconnected ( UnturnedPlayer player )
0 commit comments