| <?php | |||||
| class MinecraftPaymentPlugin extends Plugin { | |||||
| public static function get_plugin_name(): string { | |||||
| return 'Minecraft-Payment'; | |||||
| } | |||||
| public function __construct( $_DB ) { | |||||
| $this->require_class( 'RCon' ); | |||||
| } | |||||
| public function has_page(): bool { | |||||
| return true; | |||||
| } | |||||
| public function get_page_path() { | |||||
| return [ | |||||
| '/minecraft-pay/settle' => 'settle_view' | |||||
| ]; | |||||
| } | |||||
| public function pre_load_plugin(): void { | |||||
| $this->register_component_short( 'SettingsList' ); | |||||
| $this->add_route( '/minecraft-pay/settings', 'SettingsList' ); | |||||
| $this->register_component_short( 'Settings' ); | |||||
| $this->add_route( '/minecraft-pay/settings/:id', 'Settings' ); | |||||
| $this->register_component_short( 'UsersList' ); | |||||
| $this->add_route( '/minecraft-pay/users', 'UsersList' ); | |||||
| $this->register_component_short( 'MinecraftUsers' ); | |||||
| $this->add_route( '/minecraft-pay/users/:id', 'MinecraftUsers' ); | |||||
| $this->register_component_short( 'AlterAccount' ); | |||||
| $this->add_route( '/minecraft-pay/acredit', 'AlterAccount' ); | |||||
| $this->register_component_short( 'AccountList' ); | |||||
| $this->add_route( '/minecraft-pay/balance', 'AccountList' ); | |||||
| $this->register_component_short( 'GrantUser' ); | |||||
| $this->add_route( '/minecraft-pay/grant', 'GrantUser' ); | |||||
| $this->require_class( 'MinecraftPayAPI' ); | |||||
| API::REGISTER_CLASS( new MinecraftPayAPI(), 3, 'minecraft-pay/' ); | |||||
| } | |||||
| private function settle( $m, $y ) { | |||||
| $mp = MinecraftMonthPaid::GetByUnique( 0, $m ,$y ); | |||||
| if ( $mp ) { | |||||
| echo __( [ 'de' => 'Bereits abgerechnet', 'en' => 'Already settled' ] ); | |||||
| return; | |||||
| } | |||||
| $sum = 0; | |||||
| foreach ( MinecraftServer::GetAll() as $server ) { | |||||
| $m = strlen( $m ) == 2 ? $m : '0' . $m; | |||||
| $f = "$y-$m-01"; | |||||
| $cap = date( 't', strtotime( $f ) ); | |||||
| $l = "$y-$m-$cap"; | |||||
| $sid = $server->ID; | |||||
| $subscribers = MinecraftServerSubscription::GetAll( "ConcerningServerID = $sid AND SubscriptionDate BETWEEN '$f' AND '$l'" ); | |||||
| $subsCount = count( $subscribers ); | |||||
| $pot = $subsCount * $server->GetPerMonthPrice(); | |||||
| $potPart = ceil( ( $pot / $subsCount ) * 100 ) / 100; | |||||
| if ( $pot == 0 ) continue; | |||||
| $potPart *= -1; | |||||
| if ( $pot > $server->GetMaxPerMonthPrice() ) $pot = $server->GetMaxPerMonthPrice(); | |||||
| $sum += $pot; | |||||
| /* $dayssum = 0; | |||||
| $subs = []; | |||||
| $sum += $pot; | |||||
| $potheap = 0; | |||||
| $dayssumheap = 0; | |||||
| foreach( $subscribers as $subscriber ) { | |||||
| $days = date( 'd', strtotime( $subscriber->GetSubscriptionDate() ) ); | |||||
| $dayssum += $days; | |||||
| $subs[] = [ $days, $subscriber ]; | |||||
| } | |||||
| foreach ( $subs as $subscription ) { | |||||
| $price = $pot * ( $dayssum / $subscription[ 0 ] ) | |||||
| }*/ | |||||
| foreach( $subscribers as $subscriber ) { | |||||
| $u = $subscriber->GetUnlockedUser()->GetOwner(); | |||||
| $ac = new MinecraftUserAccount(); | |||||
| $ac->SetMod( $potPart ); | |||||
| $ac->SetDebtor( $u ); | |||||
| $ac->SetComment( 'Host-Relief for ' . $server->GetName() . ' for ' . $m . '-' . $y ); | |||||
| $ac->Save(); | |||||
| } | |||||
| $server->ClearWhitelist(); | |||||
| } | |||||
| $mp = new MinecraftMonthPaid(); | |||||
| $mp->SetAmount( $sum ); | |||||
| $mp->SetMonth( $m ); | |||||
| $mp->SetYear( $y ); | |||||
| if ( $mp->Save() ) { | |||||
| echo __( [ 'de' => 'Abrechnung beendet', 'en' => 'Settled' ] ); | |||||
| } | |||||
| } | |||||
| public function settle_view( string $url ) { | |||||
| // ORDER BY Year DESC, Month DESC LIMIT 1 | |||||
| $nwst = MinecraftMonthPaid::GetAll( "1 ORDER BY Year DESC, Month DESC LIMIT 1" )[ 0 ]; | |||||
| if ( !$nwst ) { | |||||
| $nwst = new MinecraftMonthPaid(); | |||||
| $nwst->SetMonth( date( 'm' ) ); | |||||
| $nwst->SetYear( date( 'Y' ) ); | |||||
| } | |||||
| $m = array_key_exists( 'month', $_GET ) ? $_GET[ 'month' ] + 1 : date( 'm' ); | |||||
| $y = array_key_exists( 'year', $_GET ) ? $_GET[ 'year' ] : date( 'Y' ); | |||||
| if ( $m == '0' ) { $m = '12'; $y--; } | |||||
| $start = ( new DateTime( $nwst->GetYear() . '-' . $nwst->GetMonth() . '-' . '01' ) )->modify( 'first day of next month' ); | |||||
| $end = ( new DateTime( date( "$y-$m-01" ) ) )->modify( 'first day of this month' ); | |||||
| $interval = DateInterval::createFromDateString( '1 month' ); | |||||
| $period = new DatePeriod( $start, $interval, $end ); | |||||
| $settled = false; | |||||
| foreach ($period as $dt) { | |||||
| $settled = true; | |||||
| echo 'Settling ' . $dt->format("Y-m") . ': '; | |||||
| $this->settle( $dt->format( 'm' ), $dt->format( 'Y' ) ); | |||||
| echo "<br>\n"; | |||||
| } | |||||
| if( !$settled ) { | |||||
| echo 'Nothing to settle'; | |||||
| } | |||||
| } | |||||
| public function load_plugin(): void { | |||||
| if ( is_null( Permission::GetByUnique( 0, 'Minecraft-Pay-Settings' ) ) ) { | |||||
| $p = Permission::FromArray( [], [] ); | |||||
| $p->SetName( 'Minecraft-Pay-Settings' ); | |||||
| $p->SetSlug( slugify( 'Minecraft-Pay-Settings' ) ); | |||||
| $p->Save(); | |||||
| } | |||||
| if ( is_null( Permission::GetByUnique( 0, 'Minecraft-Possess-User' ) ) ) { | |||||
| $p = Permission::FromArray( [], [] ); | |||||
| $p->SetName( 'Minecraft-Possess-User' ); | |||||
| $p->SetSlug( slugify( 'Minecraft-Possess-User' ) ); | |||||
| $p->Save(); | |||||
| } | |||||
| if ( User::ONLINE() && Permission::PERMITTED( 'Minecraft-Possess-User' ) ) { | |||||
| $me = new MenuEntry( 'Minecraft Payment' ); | |||||
| $me->addImageFromResource( 'minecraft.svg', MinecraftPaymentPlugin::get_plugin_name() ); | |||||
| $me->setFilter( 'none' ); | |||||
| if ( Permission::PERMITTED( 'Minecraft-Pay-Settings' ) ) { | |||||
| $sub = new MenuEntry( 'Minecraft Payment', HOME_URL . 'minecraft-pay/settings' ); | |||||
| $sub->addImageFromResource( 'settings.svg', Plugin_Plugin::get_plugin_name() ); | |||||
| $me->addSubEntry( $sub ); | |||||
| } | |||||
| $sub = new MenuEntry( [ 'de' => 'Minecraft Benutzer', 'en' => 'Minecraft Users' ], HOME_URL . 'minecraft-pay/users' ); | |||||
| $sub->addImageFromResource( 'users.svg', UserManager_Plugin::get_plugin_name() ); | |||||
| $me->addSubEntry( $sub ); | |||||
| if ( Permission::PERMITTED( 'Minecraft-Pay-Settings' ) ) { | |||||
| $sub = new MenuEntry( [ 'de' => 'Gutschrift', 'en' => 'Credit' ], HOME_URL . 'minecraft-pay/acredit' ); | |||||
| $sub->addImageFromResource( 'cash.svg', MinecraftPaymentPlugin::get_plugin_name() ); | |||||
| $me->addSubEntry( $sub ); | |||||
| } | |||||
| $sub = new MenuEntry( [ 'de' => 'Transaktionen', 'en' => 'Transactions' ], HOME_URL . 'minecraft-pay/balance' ); | |||||
| $sub->addImageFromResource( 'cash.svg', MinecraftPaymentPlugin::get_plugin_name() ); | |||||
| $me->addSubEntry( $sub ); | |||||
| if ( Permission::PERMITTED( 'Minecraft-Pay-Settings' ) ) { | |||||
| $sub = new MenuEntry( [ 'de' => 'Recht gewähren', 'en' => 'Grant right' ], HOME_URL . 'minecraft-pay/grant' ); | |||||
| $sub->addImageFromResource( 'key.svg', MinecraftPaymentPlugin::get_plugin_name() ); | |||||
| $me->addSubEntry( $sub ); | |||||
| }; | |||||
| SideMenu::addMainMenuEntry( $me ); | |||||
| } | |||||
| } | |||||
| } |
| <?php | |||||
| class MinecraftPayAPI { | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path servers | |||||
| * | |||||
| * @Request-Method GET | |||||
| * | |||||
| * @return MinecraftServer[] | |||||
| */ | |||||
| public function GetAllServers() { | |||||
| return MinecraftServer::GetAll()->toArray(); | |||||
| } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path servers/:id | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Pay-Settings | |||||
| * | |||||
| * @Request-Method PATCH | |||||
| * | |||||
| * @Parameterized | |||||
| * | |||||
| * @param MinecraftServer $server server to edit | |||||
| * | |||||
| * @paramget id path id required int | |||||
| * @paramget server post server required MinecraftServer | |||||
| * | |||||
| * @return APIResult< MinecraftServer > | |||||
| */ | |||||
| public static function UpdateServer( int $id, MinecraftServer $server ) { | |||||
| $o = MinecraftServer::GetByID( $id ); | |||||
| if ( $o == null ) { | |||||
| $results[] = new APIResult( 'Missing ID', false, $server ); | |||||
| } | |||||
| if ( $server->GetName() != null ) $o->SetName( $server->GetName() ); | |||||
| if ( $server->GetDomain() != null ) $o->SetDomain( $server->GetDomain() ); | |||||
| if ( $server->GetPort() != null ) $o->SetPort( $server->GetPort() ); | |||||
| if ( $server->GetPassword() != null ) $o->SetPassword( $server->GetPassword() ); | |||||
| if ( $server->GetServerPath() != null ) $o->SetServerPath( $server->GetServerPath() ); | |||||
| if ( $server->GetPerMonthPrice() != null ) $o->SetPerMonthPrice( $server->GetPerMonthPrice() ); | |||||
| if ( $server->GetMaxPerMonthPrice() != null ) $o->SetMaxPerMonthPrice( $server->GetMaxPerMonthPrice() ); | |||||
| $r = $o->Save(); | |||||
| return new APIResult( $r ? 'Saved successfully' : 'Saving failed', $r, $r ? $o : MinecraftServer::GetByID( $id ) ); | |||||
| } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path servers/:id | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Pay-Settings | |||||
| * | |||||
| * @Request-Method DELETE | |||||
| * | |||||
| * @Parameterized | |||||
| * | |||||
| * @paramget id path id required int | |||||
| * | |||||
| * @return APIResult< MinecraftServer > | |||||
| */ | |||||
| public static function DeleteServer( int $id ) { | |||||
| if ( !is_numeric( $id ) ) return new APIResult( 'Invalid ID', false, null ); | |||||
| $server = MinecraftServer::GetByID( $id ); | |||||
| $result = null; | |||||
| if ( !$server ) { | |||||
| $result = new APIResult( 'Server does not exist', false, null ); | |||||
| } else if ( $server->DELETE() ) { | |||||
| $result = new APIResult( 'Deleted server successfully', true, null ); | |||||
| } else { | |||||
| $result = new APIResult( 'Deleting server failed', false, $server ); | |||||
| } | |||||
| return $result; | |||||
| } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path servers | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Pay-Settings | |||||
| * | |||||
| * @Request-Method POST | |||||
| * | |||||
| * @Parameterized | |||||
| * | |||||
| * @param MinecraftServer $server to add | |||||
| * | |||||
| * @paramget server post server required MinecraftServer | |||||
| * | |||||
| * @return APIResult< MinecraftServer > | |||||
| */ | |||||
| public static function AddServer( MinecraftServer $server ) { | |||||
| $o = new MinecraftServer(); | |||||
| $o->SetName( $server->GetName() ); | |||||
| $s = $o->Save(); | |||||
| return new APIResult( $s ? 'Created server successfully' : 'The server could not be created', $s, $s ? $o : null ); | |||||
| } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path users | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Possess-User | |||||
| * | |||||
| * @Request-Method GET | |||||
| * | |||||
| * @return MinecraftUser[] | |||||
| */ | |||||
| public function GetAllUsers() { | |||||
| return MinecraftUser::GetAll( [ 'OwnerID' => API::$User->GetID() ] )->toArray(); | |||||
| } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path users/:id/subscription-states | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Possess-User | |||||
| * | |||||
| * @Request-Method GET | |||||
| * | |||||
| * @Parameterized | |||||
| * | |||||
| * @paramget id path id required int | |||||
| * | |||||
| * @return Map< int, boolean > | |||||
| */ | |||||
| public function GetAllSubscriptionStates( int $id ) { | |||||
| $user = MinecraftUser::GetByID( $id ); | |||||
| $data = []; | |||||
| foreach( MinecraftServer::GetAll() as $server ) { | |||||
| $data[] = [ $server->GetID() , $server->IsUnlocked( $user ) ]; | |||||
| } | |||||
| return $data; | |||||
| } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path users/:id/subscribe-server/:serverId | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Possess-User | |||||
| * | |||||
| * @Request-Method GET | |||||
| * | |||||
| * @Parameterized | |||||
| * | |||||
| * @paramget id path id required int | |||||
| * @paramget serverId path serverId required int | |||||
| * | |||||
| * @return APIResult< boolean > | |||||
| */ | |||||
| public function SubscribeServer( int $id, int $serverId ) { | |||||
| $u = MinecraftUser::GetByID( $id ); | |||||
| $s = MinecraftServer::GetByID( $serverId ); | |||||
| $result = new APIResult( '', false, false ); | |||||
| if ( is_null( $s ) ) { | |||||
| $result->Message( 'Unknown server' ); | |||||
| } | |||||
| else if ( is_null( $u ) ) { | |||||
| $result->Message( 'Unknown user' ); | |||||
| } | |||||
| else { | |||||
| if ( $s->Unlock( $u ) ) { | |||||
| if ( !$u->HasSubscripted( $s ) ) { | |||||
| $ms = new MinecraftServerSubscription(); | |||||
| $ms->SetConcerningServer( $s ); | |||||
| $ms->SetUnlockedUser( $u ); | |||||
| $result->Success( $ms->Save() ); | |||||
| $result->Message( $result->Success() ? 'Unlock successful' : 'Unlock failed' )->Obj( $result->Success() ); | |||||
| if ( !$result->Success() ) $s->Lock( $u ); | |||||
| } else { | |||||
| $result->Message( 'Unlock successful' )->Success( true )->Obj( true ); | |||||
| } | |||||
| } else { | |||||
| $result->Message( 'Unlock failed' )->Success( false ); | |||||
| } | |||||
| } | |||||
| return $result; | |||||
| } | |||||
| // /** | |||||
| // * @API-Callback | |||||
| // * @Path users/:id | |||||
| // * @Require-Login | |||||
| // * @Require-Permission Minecraft-Possess-User | |||||
| // * | |||||
| // * @Request-Method PATCH | |||||
| // * | |||||
| // * @Parameterized | |||||
| // * | |||||
| // * @param MinecraftUser $user user to edit | |||||
| // * | |||||
| // * @paramget id path id required int | |||||
| // * @paramget user post user required MinecraftUser | |||||
| // * | |||||
| // * @return APIResult< MinecraftUser > | |||||
| // */ | |||||
| // public static function UpdateUser( int $id, MinecraftUser $user ) { | |||||
| // $o = MinecraftUser::GetByID( $id ); | |||||
| // if ( $o == null ) { | |||||
| // $results[] = new APIResult( 'Missing ID', false, $user ); | |||||
| // } | |||||
| // if ( $user->GetUsername() != null ) $o->SetUsername( $user->GetUsername() ); | |||||
| // if ( API::$User->GetID() != $user->GetOwner()->GetID() ) { | |||||
| // return new APIResult( 'This minecraft user does not belong to you', false, null ); | |||||
| // } | |||||
| // $r = $o->Save(); | |||||
| // return new APIResult( $r ? 'Saved successfully' : 'Saving failed', $r, $r ? $o : MinecraftUser::GetByID( $id ) ); | |||||
| // } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path users/:id | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Possess-User | |||||
| * | |||||
| * @Request-Method DELETE | |||||
| * | |||||
| * @Parameterized | |||||
| * | |||||
| * @paramget id path id required int | |||||
| * | |||||
| * @return APIResult< MinecraftUser > | |||||
| */ | |||||
| public static function DeleteUser( int $id ) { | |||||
| if ( !is_numeric( $id ) ) return new APIResult( 'Invalid ID', false, null ); | |||||
| $user = MinecraftUser::GetByID( $id ); | |||||
| $result = null; | |||||
| if ( !$user ) { | |||||
| $result = new APIResult( 'User does not exist', false, null ); | |||||
| } else if ( $user->DELETE() ) { | |||||
| $result = new APIResult( 'Deleted user successfully', true, null ); | |||||
| } else { | |||||
| $result = new APIResult( 'Deleting user failed', false, $user ); | |||||
| } | |||||
| return $result; | |||||
| } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path users | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Possess-User | |||||
| * | |||||
| * @Request-Method POST | |||||
| * | |||||
| * @Parameterized | |||||
| * | |||||
| * @param MinecraftUser $user to add | |||||
| * | |||||
| * @paramget user post user required MinecraftUser | |||||
| * | |||||
| * @return APIResult< MinecraftUser > | |||||
| */ | |||||
| public static function AddUser( MinecraftUser $user ) { | |||||
| $o = new MinecraftUser(); | |||||
| $o->SetUsername( $user->GetUsername() ); | |||||
| $o->SetOwner( API::$User ); | |||||
| $s = $o->Save(); | |||||
| return new APIResult( $s ? 'Created user successfully' : 'The user could not be created', $s, $s ? $o : null ); | |||||
| } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path charges | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Possess-User | |||||
| * | |||||
| * @Request-Method GET | |||||
| * | |||||
| * @return MinecraftUserAccount[] | |||||
| */ | |||||
| public function GetAllCharges() { | |||||
| return MinecraftUserAccount::GetAll( [ 'DebtorID' => API::$User->GetID() ] )->toArray(); | |||||
| } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path users/:id/grant-user-right | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Pay-Settings | |||||
| * | |||||
| * @Request-Method POST | |||||
| * | |||||
| * @Parameterized | |||||
| * | |||||
| * @paramget id path id required int | |||||
| * | |||||
| * @return APIResult< boolean > | |||||
| */ | |||||
| public function GrantUserRight( int $id ) { | |||||
| $u = User::GetByID( $id ); | |||||
| $r = new APIResult( '', false, false ); | |||||
| $s = false; | |||||
| if ( !is_null( $u ) ) { | |||||
| $p = Permission::SEARCH( 'Minecraft-Possess-User' ); | |||||
| $s = $p->grant_user( $u->GetID(), true ); | |||||
| $r->Message( 'Right granted successfully' )->Success( true )->Obj( true ); | |||||
| } | |||||
| else $r->Message( 'Could not find user' ); | |||||
| return $r; | |||||
| } | |||||
| /** | |||||
| * @API-Callback | |||||
| * @Path users/:id/acredit | |||||
| * @Require-Login | |||||
| * @Require-Permission Minecraft-Pay-Settings | |||||
| * | |||||
| * @Request-Method POST | |||||
| * | |||||
| * @Parameterized | |||||
| * | |||||
| * @paramget id path id required int | |||||
| * @paramget credit post credit required MinecraftUserAccount | |||||
| * | |||||
| * @return APIResult< MinecraftUserAccount > | |||||
| */ | |||||
| public function Acredit( int $id, MinecraftUserAccount $credit ) { | |||||
| $r = new APIResult( '', false, null ); | |||||
| $ac = new MinecraftUserAccount(); | |||||
| $u = User::GetByID( $id ); | |||||
| if ( is_null( $u ) ) { | |||||
| $r->Message( 'Missing user' ); | |||||
| } else { | |||||
| $ac->SetMod( $credit->GetMod() ); | |||||
| $ac->SetComment( $credit->GetComment() ); | |||||
| $ac->SetDebtor( $u ); | |||||
| $r->Success( !!$ac->Save() ); | |||||
| $r->Message( $r->Success() ? 'Credit successful' : 'Credit failed' ); | |||||
| if ( $r->Success() ) $r->Obj( $ac ); | |||||
| } | |||||
| return $r; | |||||
| } | |||||
| } |
| <?php | |||||
| /** | |||||
| * See https://developer.valvesoftware.com/wiki/Source_RCON_Protocol for | |||||
| * more information about Source RCON Packets | |||||
| * | |||||
| * PHP Version 7 | |||||
| * | |||||
| * @copyright 2013-2017 Chris Churchwell | |||||
| * @author thedudeguy | |||||
| * @link https://github.com/thedudeguy/PHP-Minecraft-Rcon | |||||
| */ | |||||
| class Rcon | |||||
| { | |||||
| private $host; | |||||
| private $port; | |||||
| private $password; | |||||
| private $timeout; | |||||
| private $socket; | |||||
| private $authorized = false; | |||||
| private $lastResponse = ''; | |||||
| const PACKET_AUTHORIZE = 5; | |||||
| const PACKET_COMMAND = 6; | |||||
| const SERVERDATA_AUTH = 3; | |||||
| const SERVERDATA_AUTH_RESPONSE = 2; | |||||
| const SERVERDATA_EXECCOMMAND = 2; | |||||
| const SERVERDATA_RESPONSE_VALUE = 0; | |||||
| /** | |||||
| * Create a new instance of the Rcon class. | |||||
| * | |||||
| * @param string $host | |||||
| * @param integer $port | |||||
| * @param string $password | |||||
| * @param integer $timeout | |||||
| */ | |||||
| public function __construct($host, $port, $password, $timeout) | |||||
| { | |||||
| $this->host = $host; | |||||
| $this->port = $port; | |||||
| $this->password = $password; | |||||
| $this->timeout = $timeout; | |||||
| } | |||||
| /** | |||||
| * Get the latest response from the server. | |||||
| * | |||||
| * @return string | |||||
| */ | |||||
| public function getResponse() | |||||
| { | |||||
| return $this->lastResponse; | |||||
| } | |||||
| /** | |||||
| * Connect to a server. | |||||
| * | |||||
| * @return boolean | |||||
| */ | |||||
| public function connect() | |||||
| { | |||||
| $this->socket = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout); | |||||
| if (!$this->socket) { | |||||
| $this->lastResponse = $errstr; | |||||
| return false; | |||||
| } | |||||
| //set timeout | |||||
| stream_set_timeout($this->socket, 3, 0); | |||||
| // check authorization | |||||
| return $this->authorize(); | |||||
| } | |||||
| /** | |||||
| * Disconnect from server. | |||||
| * | |||||
| * @return void | |||||
| */ | |||||
| public function disconnect() | |||||
| { | |||||
| if ($this->socket) { | |||||
| fclose($this->socket); | |||||
| } | |||||
| $this->authorized = false; | |||||
| } | |||||
| /** | |||||
| * True if socket is connected and authorized. | |||||
| * | |||||
| * @return boolean | |||||
| */ | |||||
| public function isConnected() | |||||
| { | |||||
| return $this->authorized; | |||||
| } | |||||
| /** | |||||
| * Send a command to the connected server. | |||||
| * | |||||
| * @param string $command | |||||
| * | |||||
| * @return boolean|mixed | |||||
| */ | |||||
| public function sendCommand($command) | |||||
| { | |||||
| if (!$this->isConnected()) { | |||||
| return false; | |||||
| } | |||||
| // send command packet | |||||
| $this->writePacket(self::PACKET_COMMAND, self::SERVERDATA_EXECCOMMAND, $command); | |||||
| // get response | |||||
| $response_packet = $this->readPacket(); | |||||
| if ($response_packet['id'] == self::PACKET_COMMAND) { | |||||
| if ($response_packet['type'] == self::SERVERDATA_RESPONSE_VALUE) { | |||||
| $this->lastResponse = $response_packet['body']; | |||||
| return $response_packet['body']; | |||||
| } | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /** | |||||
| * Log into the server with the given credentials. | |||||
| * | |||||
| * @return boolean | |||||
| */ | |||||
| private function authorize() | |||||
| { | |||||
| $this->writePacket(self::PACKET_AUTHORIZE, self::SERVERDATA_AUTH, $this->password); | |||||
| $response_packet = $this->readPacket(); | |||||
| if ($response_packet['type'] == self::SERVERDATA_AUTH_RESPONSE) { | |||||
| if ($response_packet['id'] == self::PACKET_AUTHORIZE) { | |||||
| $this->authorized = true; | |||||
| return true; | |||||
| } | |||||
| } | |||||
| $this->disconnect(); | |||||
| return false; | |||||
| } | |||||
| /** | |||||
| * Writes a packet to the socket stream. | |||||
| * | |||||
| * @param $packetId | |||||
| * @param $packetType | |||||
| * @param string $packetBody | |||||
| * | |||||
| * @return void | |||||
| */ | |||||
| private function writePacket($packetId, $packetType, $packetBody) | |||||
| { | |||||
| /* | |||||
| Size 32-bit little-endian Signed Integer Varies, see below. | |||||
| ID 32-bit little-endian Signed Integer Varies, see below. | |||||
| Type 32-bit little-endian Signed Integer Varies, see below. | |||||
| Body Null-terminated ASCII String Varies, see below. | |||||
| Empty String Null-terminated ASCII String 0x00 | |||||
| */ | |||||
| //create packet | |||||
| $packet = pack('VV', $packetId, $packetType); | |||||
| $packet = $packet.$packetBody."\x00"; | |||||
| $packet = $packet."\x00"; | |||||
| // get packet size. | |||||
| $packet_size = strlen($packet); | |||||
| // attach size to packet. | |||||
| $packet = pack('V', $packet_size).$packet; | |||||
| // write packet. | |||||
| fwrite($this->socket, $packet, strlen($packet)); | |||||
| } | |||||
| /** | |||||
| * Read a packet from the socket stream. | |||||
| * | |||||
| * @return array | |||||
| */ | |||||
| private function readPacket() | |||||
| { | |||||
| //get packet size. | |||||
| $size_data = fread($this->socket, 4); | |||||
| $size_pack = unpack('V1size', $size_data); | |||||
| $size = $size_pack['size']; | |||||
| // if size is > 4096, the response will be in multiple packets. | |||||
| // this needs to be address. get more info about multi-packet responses | |||||
| // from the RCON protocol specification at | |||||
| // https://developer.valvesoftware.com/wiki/Source_RCON_Protocol | |||||
| // currently, this script does not support multi-packet responses. | |||||
| $packet_data = fread($this->socket, $size); | |||||
| $packet_pack = unpack('V1id/V1type/a*body', $packet_data); | |||||
| return $packet_pack; | |||||
| } | |||||
| } |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M32 96v256h448V96H32zm160.5 224h-80.4c0-26.6-21.5-48.1-48.1-48.1V192c35.3 0 64-28.7 64-64h64.5c-19.9 23.5-32.5 57.8-32.5 96s12.6 72.5 32.5 96zM448 271.9c-26 0-48 21.5-48 48.1h-80.5c19.9-23.5 32.5-57.8 32.5-96s-12.6-72.5-32.5-96H384c0 35.3 28.7 64 64 64v79.9zM32 384h448v32H32z"/></svg> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M435.2 80H76.8c-24.9 0-44.6 19.6-44.6 44L32 388c0 24.4 19.9 44 44.8 44h358.4c24.9 0 44.8-19.6 44.8-44V124c0-24.4-19.9-44-44.8-44zm0 308H76.8V256h358.4v132zm0-220H76.8v-44h358.4v44z"/></svg> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M249.2 224c-14.2-40.2-55.1-72-100.2-72-57.2 0-101 46.8-101 104s45.8 104 103 104c45.1 0 84.1-31.8 98.2-72H352v64h69.1v-64H464v-64H249.2zm-97.6 66.5c-19 0-34.5-15.5-34.5-34.5s15.5-34.5 34.5-34.5 34.5 15.5 34.5 34.5-15.5 34.5-34.5 34.5z"/></svg> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M376 186h-20v-40c0-55-45-100-100-100S156 91 156 146v40h-20c-22.002 0-40 17.998-40 40v200c0 22.002 17.998 40 40 40h240c22.002 0 40-17.998 40-40V226c0-22.002-17.998-40-40-40zM256 368c-22.002 0-40-17.998-40-40s17.998-40 40-40 40 17.998 40 40-17.998 40-40 40zm62.002-182H193.998v-40c0-34.004 28.003-62.002 62.002-62.002 34.004 0 62.002 27.998 62.002 62.002v40z"/></svg> |
| <svg xmlns="http://www.w3.org/2000/svg" width="480" height="480" viewBox="0 0 48 48"><path fill="#8BC34A" d="M11 7L21 7 20 11 23 11 21 16 25 16 27 11 30 11 31 7 41 7 35 33 3 33z"/><path fill="#263238" d="M40.754,6H40h-9h-0.74l-1.182,5H27.5h-1.299l-0.509,1.854L20.785,6H20h-7.266H11h-0.359h-0.01L2,33l8.908,9h0.229h2.004h7.982l1.523-6.172L23.698,37h2.62l4.104,5H30.6h1.784h8.538L46,17L40.754,6z M31.333,8h8.133l-1.808,8h-3.754l1.086-4.402c0.029-0.146-0.009-0.299-0.104-0.415C34.792,11.067,34.649,11,34.5,11h-3.908L31.333,8z M27.5,11.916V12h6.39l-1.012,4h-6.581l1.087-3.66L27.5,11.916z M18.887,11h-7.715l0.938-3h7.688L18.887,11z M12.334,33.042H4.369L4.328,33H4.297l3.125-10h1.915L7.52,29.362c-0.043,0.151-0.014,0.313,0.081,0.438C7.695,29.927,7.843,30,8,30h5.217L12.334,33.042z M9.52,26h4.858l-0.871,3H8.663L9.52,26z M25.094,33l2.628-11h-2.094h-1.121l-1.352,5H17.4l1.354-5h-3.215l-0.871,3H9.806l0.675-2.362c0.043-0.151,0.014-0.313-0.081-0.438C10.305,22.073,10.157,22,10,22H7.734l3.125-10h7.725H19h2.292l-1.354,5H25h1h11.432l-3.615,16H25.094z"/><path fill="#8D6E63" d="M18.841 40L12.334 33 4.328 33 11.182 40zM38.801 40L33.816 33 25.094 33 30.764 40zM23.036 33L23 33 24.117 28.324 23.084 27 17.484 27 24.071 35.001 24.678 35.001z"/></svg> |
| <svg xmlns='http://www.w3.org/2000/svg' width='512' height='512' viewBox='0 0 512 512'><title>ionicons-v5-b</title><path d='M256,48C141.31,48,48,141.32,48,256c0,114.86,93.14,208,208,208,114.69,0,208-93.31,208-208C464,141.13,370.87,48,256,48Zm94,219a94,94,0,1,1-94-94h4.21l-24-24L256,129.2,315.8,189,256,248.8,236.2,229l27.92-27.92C261.72,201,259,201,256,201a66,66,0,1,0,66,66V253h28Z'/></svg> |
| <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M376 186h-20v-40c0-55-45-100-100-100S156 91 156 146h37.998c0-34.004 28.003-62.002 62.002-62.002 34.004 0 62.002 27.998 62.002 62.002H318v40H136c-22.002 0-40 17.998-40 40v200c0 22.002 17.998 40 40 40h240c22.002 0 40-17.998 40-40V226c0-22.002-17.998-40-40-40zM256 368c-22.002 0-40-17.998-40-40s17.998-40 40-40 40 17.998 40 40-17.998 40-40 40z"/></svg> |
| declare class Account { | |||||
| } |
| class Account { | |||||
| } |
| class Account { | |||||
| } |
| <meta log-in /> | |||||
| <div style="width: 100%; text-align: right; border: 1px solid white; border-radius: 1rem; padding: 1rem; margin: 1rem 0; box-sizing: border-box;"> | |||||
| <span>Account: <a dval-innerText="MinecraftUserAccount::ACCOUNT() + ' €'"></a></span> | |||||
| </div> |
| declare class AccountList { | |||||
| private refresh; | |||||
| private getAccount; | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| class AccountList { | |||||
| refresh() { | |||||
| MinecraftPayService.RefreshCharges(); | |||||
| } | |||||
| getAccount() { | |||||
| return MinecraftPayService.UserAccounts.map(acc => acc.Mod).concat([0]).reduce((pre, nxt) => pre + nxt); | |||||
| } | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| class AccountList { | |||||
| private refresh() { | |||||
| MinecraftPayService.RefreshCharges(); | |||||
| } | |||||
| private getAccount() { | |||||
| return MinecraftPayService.UserAccounts.map( acc => acc.Mod ).concat( [ 0 ] ).reduce( ( pre, nxt ) => pre + nxt ); | |||||
| } | |||||
| } |
| <div class="bg-primary w-100 d-flex justify-content-end p-2 rounded"> | |||||
| <span dval-innerText="__( 'Account' ) + ': '"></span> | |||||
| <span dval-innerText="this.getAccount()"></span> | |||||
| <span> €</span> | |||||
| </div> | |||||
| <hr /> | |||||
| <table class="table table-hover table-striped"> | |||||
| <thead> | |||||
| <tr class="table-primary"> | |||||
| <th class="align-middle" dval-innerText="__( 'Date' )"></th> | |||||
| <th class="align-middle" style="width: 100%;" dval-innerText="__( 'Comment' )"></th> | |||||
| <th class="align-middle" dval-innerText="__( 'Amount' )"></th> | |||||
| <th> | |||||
| <a class="btn btn-info p-0"> | |||||
| <img dval-src="Resources.GetImageUrl( 'refresh.svg', 'Minecraft-Payment' )" | |||||
| style="filter: invert( 1 ); height: 2em;" dval-onclick="() => this.refresh()" /> | |||||
| </a> | |||||
| </th> | |||||
| </tr> | |||||
| </thead> | |||||
| <tbody> | |||||
| <tr m-for="MinecraftPayService.UserAccounts as credit"> | |||||
| <td class="align-middle" dval-innerText="credit.Occurence"></td> | |||||
| <td class="align-middle" dval-innerText="credit.Comment"></td> | |||||
| <td colspan="2" class="align-middle" style="text-align: right;" | |||||
| dval-innerText="credit.Mod + ' €'"></td> | |||||
| </tr> | |||||
| </tbody> | |||||
| </table> |
| declare class AlterAccount { | |||||
| private debtor; | |||||
| private mod; | |||||
| private comment; | |||||
| private acredit; | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| // MLQRequire: { "Plugin": "User-Manager", "Type": "Service", "Name": "UserData" } | |||||
| class AlterAccount { | |||||
| acredit() { | |||||
| MinecraftPayAPI.Acredit({ | |||||
| params: { | |||||
| id: this.debtor | |||||
| }, | |||||
| post: { | |||||
| credit: { | |||||
| Comment: this.comment, | |||||
| Mod: this.mod | |||||
| } | |||||
| } | |||||
| }).then(r => { | |||||
| Toasts.Messaged(r.Message, Toast.Load({ Type: r.Success ? 'success' : 'danger' })); | |||||
| }); | |||||
| } | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| // MLQRequire: { "Plugin": "User-Manager", "Type": "Service", "Name": "UserData" } | |||||
| class AlterAccount { | |||||
| private debtor: number; | |||||
| private mod: number; | |||||
| private comment: string; | |||||
| private acredit() { | |||||
| MinecraftPayAPI.Acredit( | |||||
| { | |||||
| params: { | |||||
| id: this.debtor | |||||
| }, | |||||
| post: { | |||||
| credit: { | |||||
| Comment: this.comment, | |||||
| Mod: this.mod | |||||
| } as MinecraftUserAccount | |||||
| } | |||||
| } | |||||
| ).then( r => { | |||||
| Toasts.Messaged( r.Message, Toast.Load( { Type: r.Success ? 'success' : 'danger' } ) ); | |||||
| } ); | |||||
| } | |||||
| } |
| <form m-form="this.acredit"> | |||||
| <table class="table table-striped table-hover"> | |||||
| <thead> | |||||
| <tr class="table-primary"> | |||||
| <th innerText="Minecraft Payment" colspan="2"></th> | |||||
| </tr> | |||||
| </thead> | |||||
| <tbody> | |||||
| <tr> | |||||
| <th class="align-middle" dval-innerText="__( 'User' )"></th> | |||||
| <td> | |||||
| <select class="form-control" name="DebtorID" m-value="this.debtor"> | |||||
| <option dval-innerText="__( '-- Please select --' )"></option> | |||||
| <option m-for="UserData.Users as user" dval-value="user.ID" dval-innerText="user.Username"></option> | |||||
| </select> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | |||||
| <th class="align-middle" dval-innerText="__( 'Amount' )"></th> | |||||
| <td> | |||||
| <input class="form-control" type="number" step="0.01" name="Mod" value="0.00" m-value="this.mod" /> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | |||||
| <th class="align-middle" dval-innerText="__( 'Comment' )"></th> | |||||
| <td> | |||||
| <input class="form-control" type="string" name="Comment" m-value="this.comment" /> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td colspan="2"> | |||||
| <input class="form-control btn-info" type="submit" name="AddAccountChange" dval-value="__( 'Credit' )" /> | |||||
| </td> | |||||
| </tr> | |||||
| </tbody> | |||||
| </table> | |||||
| </form> |
| declare class GrantUser { | |||||
| private user; | |||||
| private grant; | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| // MLQRequire: { "Plugin": "User-Manager", "Type": "Service", "Name": "UserData" } | |||||
| class GrantUser { | |||||
| grant() { | |||||
| MinecraftPayAPI.GrantUserRight({ params: { id: this.user } }).then(r => { | |||||
| Toasts.Messaged(r.Message, Toast.Load({ Type: r.Success ? 'success' : 'danger' })); | |||||
| }); | |||||
| } | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| // MLQRequire: { "Plugin": "User-Manager", "Type": "Service", "Name": "UserData" } | |||||
| class GrantUser { | |||||
| private user: number; | |||||
| private grant() { | |||||
| MinecraftPayAPI.GrantUserRight( { params: { id: this.user } } ).then( r => { | |||||
| Toasts.Messaged( r.Message, Toast.Load( { Type: r.Success ? 'success' : 'danger' } ) ); | |||||
| } ); | |||||
| } | |||||
| } |
| <form m-form="this.grant"> | |||||
| <table class="table table-hover table-striped"> | |||||
| <thead> | |||||
| <tr class="table-primary"> | |||||
| <th innerText="Minecraft Payment" colspan="2"></th> | |||||
| </tr> | |||||
| </thead> | |||||
| <tbody> | |||||
| <tr> | |||||
| <th class="align-middle" dval-innerText="__( 'User' )"></th> | |||||
| <td> | |||||
| <select class="form-control" name="ID" m-value="this.user"> | |||||
| <option dval-innerText="__( '-- Please select --' )"></option> | |||||
| <option m-for="UserData.Users as user" dval-value="user.ID" dval-innerText="user.Username"></option> | |||||
| </select> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td colspan="2"> | |||||
| <input class="form-control btn-info" type="submit" name="GrantUserRights" dval-value="__( 'Mark as Minecraft Payment User' )" /> | |||||
| </td> | |||||
| </tr> | |||||
| </tbody> | |||||
| </table> | |||||
| </form> |
| declare class MinecraftUsers { | |||||
| private user; | |||||
| private subscriptionsStates; | |||||
| onview(vnode: any): void; | |||||
| private loadUser; | |||||
| private UnlockServer; | |||||
| private unlockServer; | |||||
| constructor(); | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| class MinecraftUsers { | |||||
| constructor() { | |||||
| this.user = {}; | |||||
| this.subscriptionsStates = new Map(); | |||||
| } | |||||
| onview(vnode) { | |||||
| if (typeof (MinecraftUser) !== 'function') | |||||
| LoadQueue.Start(() => { }); | |||||
| else | |||||
| this.loadUser(); | |||||
| } | |||||
| loadUser() { | |||||
| var id = m.route.param('id'); | |||||
| if (id.match(/^[0-9]+$/)) | |||||
| id = +id; | |||||
| else | |||||
| return; | |||||
| if (this.user.ID !== id) { | |||||
| this.user = $.extend(true, new MinecraftUser(), MinecraftPayService.Users.find(o => o.ID === id)) || this.user; | |||||
| if (this.user.ID) { | |||||
| MinecraftPayAPI.GetAllSubscriptionStates({ params: { id } }).then(map => { | |||||
| this.subscriptionsStates = map || this.subscriptionsStates; | |||||
| }); | |||||
| } | |||||
| m.redraw(); | |||||
| } | |||||
| } | |||||
| UnlockServer(serverId) { | |||||
| if (!this.subscriptionsStates.get(serverId)) { | |||||
| Modal.YesNo('Delete minecraft user', __('Do you really want to unlock this server for this minecraft user?'), (c, e) => this.unlockServer(this.user.ID, serverId, c)).Show(); | |||||
| } | |||||
| } | |||||
| unlockServer(userId, serverId, confirmed) { | |||||
| if (confirmed) { | |||||
| MinecraftPayAPI.SubscribeServer({ params: { id: userId, serverId } }).then(r => { | |||||
| this.subscriptionsStates.set(serverId, r.Obj); | |||||
| Toasts.Messaged(r.Message, Toast.Load({ Type: r.Success ? 'success' : 'danger' })); | |||||
| }); | |||||
| } | |||||
| return undefined; | |||||
| } | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| class MinecraftUsers { | |||||
| private user: MinecraftUser = {} as MinecraftUser; | |||||
| private subscriptionsStates: Map< number, boolean > = new Map(); | |||||
| public onview( vnode ) | |||||
| { | |||||
| if ( typeof( MinecraftUser ) !== 'function' ) LoadQueue.Start( () => {} ) | |||||
| else this.loadUser(); | |||||
| } | |||||
| private loadUser() { | |||||
| var id: string | number = m.route.param( 'id' ); | |||||
| if ( id.match( /^[0-9]+$/ ) ) id = +id; | |||||
| else return; | |||||
| if ( this.user.ID !== id ) { | |||||
| this.user = $.extend( true, new MinecraftUser(), MinecraftPayService.Users.find( o => o.ID === id ) ) || this.user; | |||||
| if ( this.user.ID ) { | |||||
| MinecraftPayAPI.GetAllSubscriptionStates( { params: { id } } ).then( map => { | |||||
| this.subscriptionsStates = map || this.subscriptionsStates; | |||||
| } ); | |||||
| } | |||||
| m.redraw(); | |||||
| } | |||||
| } | |||||
| private UnlockServer( serverId: number ) { | |||||
| if ( !this.subscriptionsStates.get( serverId ) ) { | |||||
| Modal.YesNo( | |||||
| 'Delete minecraft user', __( 'Do you really want to unlock this server for this minecraft user?' ), | |||||
| ( c, e ) => this.unlockServer( this.user.ID, serverId, c ) | |||||
| ).Show(); | |||||
| } | |||||
| } | |||||
| private unlockServer( userId: number, serverId: number, confirmed: boolean ): boolean { | |||||
| if ( confirmed ) { | |||||
| MinecraftPayAPI.SubscribeServer( { params: { id: userId, serverId } } ).then( r => { | |||||
| this.subscriptionsStates.set( serverId, r.Obj ); | |||||
| Toasts.Messaged( r.Message, Toast.Load( { Type: r.Success ? 'success' : 'danger' } ) ); | |||||
| } ); | |||||
| } | |||||
| return undefined; | |||||
| } | |||||
| public constructor() { | |||||
| } | |||||
| } |
| <table class="table table-striped table-hover"> | |||||
| <thead> | |||||
| <tr class="table-primary"> | |||||
| <th dval-innerText="this.user.Username" colspan="2"></th> | |||||
| </tr> | |||||
| </thead> | |||||
| <tbody> | |||||
| <tr class="table-primary"> | |||||
| <th colspan="2" dval-innerText="__('Server')"></th> | |||||
| </tr> | |||||
| <tr m-for="MinecraftPayService.Servers as server"> | |||||
| <td class="align-middle" style="vertical-align: middle; width: 100%" dval-innerText="server.Name"></td> | |||||
| <td class="align-middle"> | |||||
| <span m-if="this.subscriptionsStates.has( server.ID )" dval-onclick="() => this.UnlockServer( server.ID )" dval-class="'d-flex align-items-center btn ' + ( this.subscriptionsStates.get( server.ID ) ? 'btn-success' : 'btn-danger' )"> | |||||
| <span m-if="!this.subscriptionsStates.get( server.ID )" dval-innerText="__( 'Unlock' ) + ' ~' + server.PerMonthPrice + ' € '"></span> | |||||
| <img class="float-right" style="height: 1em; filter: invert( 1 ); vertical-align: middle;" dval-src="Resources.GetImageUrl( this.subscriptionsStates.get( server.ID ) ? 'unlock.svg' : 'lock.svg', 'Minecraft-Payment' )" /> | |||||
| </span> | |||||
| </td> | |||||
| </tr> | |||||
| </tbody> | |||||
| </table> |
| declare class Settings { | |||||
| private settings; | |||||
| onview(vnode: any): void; | |||||
| private loadServer; | |||||
| constructor(); | |||||
| private saveServer; | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| class Settings { | |||||
| constructor() { | |||||
| this.settings = {}; | |||||
| } | |||||
| onview(vnode) { | |||||
| if (typeof (MinecraftServer) !== 'function') | |||||
| LoadQueue.Start(() => { }); | |||||
| else | |||||
| this.loadServer(); | |||||
| } | |||||
| loadServer() { | |||||
| var id = m.route.param('id'); | |||||
| if (id.match(/^[0-9]+$/)) | |||||
| id = parseInt(id); | |||||
| else | |||||
| return; | |||||
| if (this.settings.ID !== id) { | |||||
| this.settings = $.extend(true, new MinecraftServer(), MinecraftPayService.Servers.find(o => o.ID === id)) || this.settings; | |||||
| m.redraw(); | |||||
| } | |||||
| } | |||||
| saveServer() { | |||||
| MinecraftPayService.UpdateServer(this.settings.ID, this.settings); | |||||
| } | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| class Settings { | |||||
| private settings: MinecraftServer = {} as MinecraftServer; | |||||
| public onview( vnode ) | |||||
| { | |||||
| if ( typeof( MinecraftServer ) !== 'function' ) LoadQueue.Start( () => {} ) | |||||
| else this.loadServer(); | |||||
| } | |||||
| private loadServer() { | |||||
| var id: string | number = m.route.param( 'id' ); | |||||
| if ( id.match( /^[0-9]+$/ ) ) id = parseInt( id ); | |||||
| else return; | |||||
| if ( this.settings.ID !== id ) { | |||||
| this.settings = $.extend( true, new MinecraftServer(), MinecraftPayService.Servers.find( o => o.ID === id ) ) || this.settings; | |||||
| m.redraw(); | |||||
| } | |||||
| } | |||||
| public constructor() { | |||||
| } | |||||
| private saveServer() { | |||||
| MinecraftPayService.UpdateServer( this.settings.ID, this.settings ); | |||||
| } | |||||
| } |
| <form m-form="this.saveServer" m-if="m.route.param( 'id' ).match( /^([0-9]+|me)$/ )"> | |||||
| <table class="table table-striped table-hover"> | |||||
| <thead> | |||||
| <tr class="table-primary"> | |||||
| <th dval-innerText="'Minecraft Payment Server ' + __( 'Settings' )" colspan="2"></th> | |||||
| </tr> | |||||
| </thead> | |||||
| <tbody> | |||||
| <tr> | |||||
| <th class="align-middle" dval-innerText="__( 'Domain' )"></th> | |||||
| <td> | |||||
| <input class="form-control" type="text" name="Domain" m-value="this.settings.Domain" /> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | |||||
| <th class="align-middle" dval-innerText="__( 'Port' )"></th> | |||||
| <td> | |||||
| <input class="form-control" type="number" name="Port" m-value="this.settings.Port" /> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | |||||
| <th class="align-middle" dval-innerText="__( 'Password' )"></th> | |||||
| <td> | |||||
| <input autocomplete="password" class="form-control" type="password" name="Password" m-value="this.settings.Password" /> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | |||||
| <th class="align-middle" dval-innerText="__( 'Server-Path' )"></th> | |||||
| <td> | |||||
| <input class="form-control" type="text" name="ServerPath" m-value="this.settings.ServerPath" /> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | |||||
| <th class="align-middle" dval-innerText="__( 'Price/Month' )"></th> | |||||
| <td> | |||||
| <input class="form-control" type="number" name="PerMonthPrice" m-value="this.settings.PerMonthPrice" /> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | |||||
| <th class="align-middle" dval-innerText="__( 'Price/Month (Limit)' )"></th> | |||||
| <td> | |||||
| <input class="form-control" type="number" name="MaxPerMonthPrice" m-value="this.settings.MaxPerMonthPrice" /> | |||||
| </td> | |||||
| </tr> | |||||
| <tr> | |||||
| <td colspan="2"> | |||||
| <input class="btn btn-primary w-100" type="submit" name="SaveServerSettings" m-value="__( 'Save' )" /> | |||||
| </td> | |||||
| </tr> | |||||
| </tbody> | |||||
| </table> | |||||
| </form> | |||||
| <h3 m-if="!m.route.param( 'id' ).match( /^([0-9]+|me)$/ )" dval-innerText="__( 'Invalid ID given' )"></h3> |
| declare class SettingsList { | |||||
| private serverName; | |||||
| private addServer; | |||||
| private deleteServer; | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| class SettingsList { | |||||
| addServer() { | |||||
| MinecraftPayService.CreateServer({ Name: this.serverName }); | |||||
| } | |||||
| deleteServer(id, confirm, event) { | |||||
| if (confirm) { | |||||
| MinecraftPayService.DeleteServer(id); | |||||
| } | |||||
| } | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| class SettingsList { | |||||
| private serverName: string; | |||||
| private addServer() { | |||||
| MinecraftPayService.CreateServer( { Name: this.serverName } as MinecraftServer ); | |||||
| } | |||||
| private deleteServer( id: number, confirm: boolean, event: any ) { | |||||
| if ( confirm ) { | |||||
| MinecraftPayService.DeleteServer( id ); | |||||
| } | |||||
| } | |||||
| } |
| <meta log-in permission="Minecraft-Pay-Settings" /> | |||||
| <form m-form="this.addServer"> | |||||
| <table class="table table-hover table-striped"> | |||||
| <tbody> | |||||
| <tr> | |||||
| <td><input class="form-control" type="text" name="Name" m-value="this.serverName" /></td> | |||||
| <td><input class="form-control btn-info" type="submit" name="CreateServer" dval-value="__( 'Create server' )" /></td> | |||||
| </tr> | |||||
| </tbody> | |||||
| </table> | |||||
| </form> | |||||
| <hr /> | |||||
| <table class="table table-hover table-striped"> | |||||
| <thead> | |||||
| <tr class="table-primary"> | |||||
| <th style="width: 100%;">Name</th> | |||||
| <th colspan="2"></th> | |||||
| </tr> | |||||
| </thead> | |||||
| <tbody> | |||||
| <tr m-for="MinecraftPayService.Servers as server"> | |||||
| <td class="align-middle" dval-innerText="server.Name"></td> | |||||
| <td class="align-middle"> | |||||
| <a class="action_href action_delete btn btn-danger" style="cursor: pointer;" dval-onclick="() => Modal.YesNo( 'Delete server', __( 'Do you really want to delete this server?' ), ( c, e ) => this.deleteServer( server.ID, c, e ) ).Show()">🗑</a> | |||||
| </td> | |||||
| <td class="align-middle"> | |||||
| <a class="action_href btn btn-outline-primary float-right" dval-m-href="'/minecraft-pay/settings/' + server.ID">>></a> | |||||
| </td> | |||||
| </tr> | |||||
| </tbody> | |||||
| </table> |
| declare class UsersList { | |||||
| private username; | |||||
| private addUser; | |||||
| private deleteUser; | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| class UsersList { | |||||
| addUser() { | |||||
| MinecraftPayService.CreateUser({ Username: this.username }); | |||||
| } | |||||
| deleteUser(id, confirm, event) { | |||||
| if (confirm) { | |||||
| MinecraftPayService.DeleteUser(id); | |||||
| } | |||||
| } | |||||
| } |
| // MLQRequire: { "Plugin": "Minecraft-Payment", "Type": "Service", "Name": "MinecraftPayService" } | |||||
| class UsersList { | |||||
| private username: string; | |||||
| private addUser() { | |||||
| MinecraftPayService.CreateUser( { Username: this.username } as MinecraftUser ); | |||||
| } | |||||
| private deleteUser( id: number, confirm: boolean, event: any ) { | |||||
| if ( confirm ) { | |||||
| MinecraftPayService.DeleteUser( id ); | |||||
| } | |||||
| } | |||||
| } |
| <form m-form="this.addUser"> | |||||
| <table class="table table-hover table-striped"> | |||||
| <tbody> | |||||
| <tr> | |||||
| <td><input class="form-control" type="text" name="Username" dval-placeholder="__( 'Username' )" m-value="this.username" /></td> | |||||
| <td><input class="form-control btn-info" type="submit" name="CreateMinecraftUser" dval-value="__( 'Add Minecraft User' )" /></td> | |||||
| </tr> | |||||
| </tbody> | |||||
| </table> | |||||
| </form> | |||||
| <hr /> | |||||
| <table class="table"> | |||||
| <thead> | |||||
| <tr class="table-primary"> | |||||
| <th style="width: 100%;">Name</th> | |||||
| <th colspan="2"></th> | |||||
| </tr> | |||||
| </thead> | |||||
| <tbody> | |||||
| <tr m-for="MinecraftPayService.Users as user"> | |||||
| <td class="align-middle" dval-innerText="user.Username"></td> | |||||
| <td class="align-middle"> | |||||
| <a class="action_href action_delete btn btn-danger" style="cursor: pointer;" dval-onclick="() => Modal.YesNo( 'Delete minecraft user', __( 'Do you really want to delete this minecraft user?' ), ( c, e ) => this.deleteUser( user.ID, c, e ) ).Show()">🗑</a> | |||||
| </td> | |||||
| <td class="align-middle"> | |||||
| <a class="action_href btn btn-outline-primary float-right" dval-m-href="'/minecraft-pay/users/' + user.ID">>></a> | |||||
| </td> | |||||
| </tr> | |||||
| </tbody> | |||||
| </table> |
| { | |||||
| "Minecraft Users": "Minecraft Benutzer", | |||||
| "Credit": "Gutschrift", | |||||
| "Transactions": "Transaktionen", | |||||
| "Grant right": "Recht gewähren", | |||||
| "Create server": "Server anlegen", | |||||
| "Domain": "Domäne", | |||||
| "Server-Path": "Server-Pfad", | |||||
| "Price/Month": "Preis/Monat", | |||||
| "Price/Month (Limit)": "Preis/Monat (Limit)", | |||||
| "Settings": "Einstellungen", | |||||
| "Delete server": "Server löschen", | |||||
| "Do you really want to delete this server?": "Willst du diesen Server wirklich löschen?", | |||||
| "Yes": "Ja", | |||||
| "No": "Nein", | |||||
| "User": "Benutzer", | |||||
| "Amount": "Menge", | |||||
| "Comment": "Kommentar", | |||||
| "Mark as Minecraft Payment User": "Als Minecraft Payment Nutzer markieren", | |||||
| "Date": "Datum", | |||||
| "Account": "Konto-Stand", | |||||
| "-- Please select --": "-- Bitte auswählen --", | |||||
| "Add Minecraft User": "Minecraft Benutzer hinzufügen" | |||||
| } |
| /// <reference types="assets/plugins/mithril/mithril/generated/apirequestimports" /> | |||||
| declare class MinecraftPayService { | |||||
| static INSTANCE: MinecraftPayService; | |||||
| static Servers: MinecraftServer[]; | |||||
| static Users: MinecraftUser[]; | |||||
| static UserAccounts: MinecraftUserAccount[]; | |||||
| private constructor(); | |||||
| static RefreshCharges(): void; | |||||
| static CreateServer(server: MinecraftServer): void; | |||||
| static UpdateServer(id: number, server: MinecraftServer): void; | |||||
| static DeleteServer(id: number): void; | |||||
| static CreateUser(user: MinecraftUser): void; | |||||
| static DeleteUser(id: number): void; | |||||
| } |
| /// <reference path="../../../../assets/plugins/mithril/mithril/generated/APIRequestImports.d.ts" /> | |||||
| // MLQRequire: { "Type": "API", "Name": "MinecraftPayAPI" } | |||||
| // MLQRequire: { "Plugin": "Mithril", "Type": "Component", "Name": "Toasts" } | |||||
| class MinecraftPayService { | |||||
| constructor() { | |||||
| LoadQueue.Start(() => { | |||||
| MinecraftPayAPI.GetAllServers().then(s => MinecraftPayService.Servers = s || []); | |||||
| MinecraftPayAPI.GetAllUsers().then(u => MinecraftPayService.Users = u || []); | |||||
| MinecraftPayAPI.GetAllCharges().then(mua => MinecraftPayService.UserAccounts = mua || []); | |||||
| }); | |||||
| } | |||||
| static RefreshCharges() { | |||||
| LoadQueue.Start(() => { | |||||
| MinecraftPayAPI.GetAllCharges().then(mua => MinecraftPayService.UserAccounts = mua || []); | |||||
| }); | |||||
| } | |||||
| static CreateServer(server) { | |||||
| MinecraftPayAPI.AddServer({ post: { server } }).then(r => { | |||||
| if (r.Success) { | |||||
| this.Servers.push(r.Obj); | |||||
| } | |||||
| Toasts.Messaged(r.Message, Toast.Load({ Type: r.Success ? 'success' : 'danger' })); | |||||
| }); | |||||
| } | |||||
| static UpdateServer(id, server) { | |||||
| MinecraftPayAPI.UpdateServer({ post: { server }, params: { id } }).then(r => { | |||||
| if (r.Success) { | |||||
| this.Servers[this.Servers.findIndex(o => o.ID === r.Obj.ID)] = r.Obj; | |||||
| } | |||||
| Toasts.Messaged(r.Message, Toast.Load({ Type: r.Success ? 'success' : 'danger' })); | |||||
| }); | |||||
| } | |||||
| static DeleteServer(id) { | |||||
| MinecraftPayAPI.DeleteServer({ params: { id } }).then(r => { | |||||
| if (r.Success) { | |||||
| this.Servers.splice(this.Servers.findIndex(o => o.ID === id), 1); | |||||
| } | |||||
| Toasts.Messaged(r.Message, Toast.Load({ Type: r.Success ? 'success' : 'danger' })); | |||||
| }); | |||||
| } | |||||
| static CreateUser(user) { | |||||
| MinecraftPayAPI.AddUser({ post: { user } }).then(r => { | |||||
| if (r.Success) { | |||||
| this.Users.push(r.Obj); | |||||
| } | |||||
| Toasts.Messaged(r.Message, Toast.Load({ Type: r.Success ? 'success' : 'danger' })); | |||||
| }); | |||||
| } | |||||
| // public static UpdateUser( id: number, user: MinecraftUser ) { | |||||
| // MinecraftPayAPI.UpdateUser( { post: { user }, params: { id } } ).then( r => { | |||||
| // if ( r.Success ) { | |||||
| // this.Users[ this.Users.findIndex( o => o.ID === r.Obj.ID ) ] = r.Obj; | |||||
| // } | |||||
| // Toasts.Messaged( r.Message, Toast.Load( { Type: r.Success ? 'success' : 'danger' } ) ); | |||||
| // } ); | |||||
| // } | |||||
| static DeleteUser(id) { | |||||
| MinecraftPayAPI.DeleteUser({ params: { id } }).then(r => { | |||||
| if (r.Success) { | |||||
| this.Users.splice(this.Users.findIndex(o => o.ID === id), 1); | |||||
| } | |||||
| Toasts.Messaged(r.Message, Toast.Load({ Type: r.Success ? 'success' : 'danger' })); | |||||
| }); | |||||
| } | |||||
| } | |||||
| MinecraftPayService.INSTANCE = new MinecraftPayService(); | |||||
| MinecraftPayService.Servers = []; | |||||
| MinecraftPayService.Users = []; | |||||
| MinecraftPayService.UserAccounts = []; |
| /// <reference path="../../../../assets/plugins/mithril/mithril/generated/APIRequestImports.d.ts" /> | |||||
| // MLQRequire: { "Type": "API", "Name": "MinecraftPayAPI" } | |||||
| // MLQRequire: { "Plugin": "Mithril", "Type": "Component", "Name": "Toasts" } | |||||
| class MinecraftPayService { | |||||
| public static INSTANCE: MinecraftPayService = new MinecraftPayService(); | |||||
| public static Servers: MinecraftServer[] = []; | |||||
| public static Users: MinecraftUser[] = []; | |||||
| public static UserAccounts: MinecraftUserAccount[] = []; | |||||
| private constructor() { | |||||
| LoadQueue.Start( () => { | |||||
| MinecraftPayAPI.GetAllServers().then( s => MinecraftPayService.Servers = s || [] ); | |||||
| MinecraftPayAPI.GetAllUsers().then( u => MinecraftPayService.Users = u || [] ); | |||||
| MinecraftPayAPI.GetAllCharges().then( mua => MinecraftPayService.UserAccounts = mua || [] ); | |||||
| } ); | |||||
| } | |||||
| public static RefreshCharges() { | |||||
| LoadQueue.Start( () => { | |||||
| MinecraftPayAPI.GetAllCharges().then( mua => MinecraftPayService.UserAccounts = mua || [] ); | |||||
| } ); | |||||
| } | |||||
| public static CreateServer( server: MinecraftServer ) { | |||||
| MinecraftPayAPI.AddServer( { post: { server } } ).then( r => { | |||||
| if ( r.Success ) { | |||||
| this.Servers.push( r.Obj ); | |||||
| } | |||||
| Toasts.Messaged( r.Message, Toast.Load( { Type: r.Success ? 'success' : 'danger' } ) ); | |||||
| } ); | |||||
| } | |||||
| public static UpdateServer( id: number, server: MinecraftServer ) { | |||||
| MinecraftPayAPI.UpdateServer( { post: { server }, params: { id } } ).then( r => { | |||||
| if ( r.Success ) { | |||||
| this.Servers[ this.Servers.findIndex( o => o.ID === r.Obj.ID ) ] = r.Obj; | |||||
| } | |||||
| Toasts.Messaged( r.Message, Toast.Load( { Type: r.Success ? 'success' : 'danger' } ) ); | |||||
| } ); | |||||
| } | |||||
| public static DeleteServer( id: number ) { | |||||
| MinecraftPayAPI.DeleteServer( { params: { id } } ).then( r => { | |||||
| if ( r.Success ) { | |||||
| this.Servers.splice( this.Servers.findIndex( o => o.ID === id ), 1 ); | |||||
| } | |||||
| Toasts.Messaged( r.Message, Toast.Load( { Type: r.Success ? 'success' : 'danger' } ) ); | |||||
| } ); | |||||
| } | |||||
| public static CreateUser( user: MinecraftUser ) { | |||||
| MinecraftPayAPI.AddUser( { post: { user } } ).then( r => { | |||||
| if ( r.Success ) { | |||||
| this.Users.push( r.Obj ); | |||||
| } | |||||
| Toasts.Messaged( r.Message, Toast.Load( { Type: r.Success ? 'success' : 'danger' } ) ); | |||||
| } ); | |||||
| } | |||||
| // public static UpdateUser( id: number, user: MinecraftUser ) { | |||||
| // MinecraftPayAPI.UpdateUser( { post: { user }, params: { id } } ).then( r => { | |||||
| // if ( r.Success ) { | |||||
| // this.Users[ this.Users.findIndex( o => o.ID === r.Obj.ID ) ] = r.Obj; | |||||
| // } | |||||
| // Toasts.Messaged( r.Message, Toast.Load( { Type: r.Success ? 'success' : 'danger' } ) ); | |||||
| // } ); | |||||
| // } | |||||
| public static DeleteUser( id: number ) { | |||||
| MinecraftPayAPI.DeleteUser( { params: { id } } ).then( r => { | |||||
| if ( r.Success ) { | |||||
| this.Users.splice( this.Users.findIndex( o => o.ID === id ), 1 ); | |||||
| } | |||||
| Toasts.Messaged( r.Message, Toast.Load( { Type: r.Success ? 'success' : 'danger' } ) ); | |||||
| } ); | |||||
| } | |||||
| } |
| <?php | |||||
| /** | |||||
| * @Name minecraft_month_paid | |||||
| * @Unique Month, Year | |||||
| */ | |||||
| class MinecraftMonthPaid extends Entity { | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name ID | |||||
| * @Type INT | |||||
| * @Primary | |||||
| * @AutoIncrement | |||||
| * @NotNull | |||||
| */ | |||||
| public $ID; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Amount | |||||
| * @Type DECIMAL(10,2) | |||||
| * @NotNull | |||||
| */ | |||||
| public $Amount; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Month | |||||
| * @Type INT(4) | |||||
| * @NotNull | |||||
| */ | |||||
| public $Month; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Year | |||||
| * @Type INT | |||||
| * @NotNull | |||||
| */ | |||||
| public $Year; | |||||
| } |
| <?php | |||||
| /** | |||||
| * @Name minecraft_server | |||||
| * @Unique Name | |||||
| * @Unique Domain, Port | |||||
| */ | |||||
| class MinecraftServer extends Entity { | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name ID | |||||
| * @Type INT | |||||
| * @Primary | |||||
| * @AutoIncrement | |||||
| * @NotNull | |||||
| */ | |||||
| public $ID; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Name | |||||
| * @Type VARCHAR(256) | |||||
| * @NotNull | |||||
| */ | |||||
| public $Name; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Domain | |||||
| * @Type VARCHAR(256) | |||||
| */ | |||||
| public $Domain = null; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Port | |||||
| * @Type INT(4) | |||||
| */ | |||||
| public $Port = null; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Password | |||||
| * @Type VARCHAR(256) | |||||
| */ | |||||
| public $Password = null; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name ServerPath | |||||
| * @Type VARCHAR(256) | |||||
| */ | |||||
| public $ServerPath = null; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name PerMonthPrice | |||||
| * @Type INT(4) | |||||
| */ | |||||
| public $PerMonthPrice = null; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name MaxPerMonthPrice | |||||
| * @Type INT(4) | |||||
| */ | |||||
| public $MaxPerMonthPrice = null; | |||||
| /** | |||||
| * @DB-Relation | |||||
| * @Field ID | |||||
| * @FieldName SubscriptionID | |||||
| * @OneToMany | |||||
| * @OnUpdate CASCADE | |||||
| * @OnDelete CASCADE | |||||
| * @var MinecraftServerSubscription[] | |||||
| */ | |||||
| public $Subscriptions; | |||||
| public function IsUnlocked( MinecraftUser $user ): bool { | |||||
| return in_array( strtolower( $user->GetUsername() ), $this->GetWhitelistedNames() ); | |||||
| } | |||||
| private $RCon = null; | |||||
| private function GetRCon() { | |||||
| if ( $this->RCon == null ) $this->RCon = new Rcon( $this->GetDomain(), $this->GetPort(), $this->GetPassword(), 1500 ); | |||||
| return $this->RCon; | |||||
| } | |||||
| public function Unlock( MinecraftUser $user, bool $keepOpen = false ): bool { | |||||
| $rcon = $this->GetRCon(); | |||||
| if ( !$rcon->isConnected() ) $rcon->connect(); | |||||
| $rcon->sendCommand( 'whitelist add ' . $user->GetUsername() ); | |||||
| $res = $rcon->getResponse(); | |||||
| if ( !$keepOpen ) $rcon->disconnect(); | |||||
| return $this->IsUnlocked( $user ); | |||||
| } | |||||
| public function Lock( MinecraftUser $user, bool $keepOpen = false ): bool { | |||||
| $rcon = $this->GetRCon(); | |||||
| if ( !$rcon->isConnected() ) $rcon->connect(); | |||||
| $rcon->sendCommand( 'whitelist remove ' . $user->GetUsername() ); | |||||
| $res = $rcon->getResponse(); | |||||
| if ( !$keepOpen ) $rcon->disconnect(); | |||||
| return !$this->IsUnlocked( $user ); | |||||
| } | |||||
| public function GetWhitelistedNames( bool $keepOpen = false ) { | |||||
| // There are 1 whitelisted players: DragonSkills99 | |||||
| $rcon = $this->GetRCon(); | |||||
| if ( !$rcon->isConnected() ) $rcon->connect(); | |||||
| $rcon->sendCommand( 'whitelist list' ); | |||||
| $res = $rcon->getResponse(); | |||||
| if ( !$keepOpen ) $rcon->disconnect(); | |||||
| if ( nocase_compare( 'There are no whitelisted players', trim( $res ) ) ) return []; | |||||
| preg_match( '/^There are [0-9]+ whitelisted players: (.*)/', trim( $res ), $m ); | |||||
| if ( !isset( $m[ 1 ] ) ) return []; | |||||
| $players = explode( ', ', strtolower( $m[ 1 ] ) ); | |||||
| if ( trim( $players[ 0 ] ) == '' ) return []; | |||||
| else return $players; | |||||
| } | |||||
| public function ClearWhitelist( int $tries = 3 ) { | |||||
| $rcon = $this->GetRCon(); | |||||
| $players = $this->GetWhitelistedNames( true ); | |||||
| if ( !count( $players ) ) { $rcon->disconnect(); return true; } | |||||
| foreach( $players as $player ) { | |||||
| $rcon->sendCommand( "whitelist remove $player" ); | |||||
| } | |||||
| $nplayers = $this->GetWhitelistedNames( true ); | |||||
| if ( count( $nplayers ) ) { | |||||
| if ( $tries > 0 ) $this->ClearWhitelist( $tries - 1 ); | |||||
| else { $rcon->disconnect(); return false; } | |||||
| } | |||||
| $rcon->disconnect(); | |||||
| return true; | |||||
| } | |||||
| } |
| <?php | |||||
| /** | |||||
| * @Name minecraft_server_subscription | |||||
| */ | |||||
| class MinecraftServerSubscription extends Entity { | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name ID | |||||
| * @Type INT | |||||
| * @Primary | |||||
| * @AutoIncrement | |||||
| * @NotNull | |||||
| */ | |||||
| public $ID; | |||||
| /** | |||||
| * @DB-Relation | |||||
| * @Field ID | |||||
| * @FieldName ConcerningServerID | |||||
| * @ManyToOne | |||||
| * @OnUpdate CASCADE | |||||
| * @OnDelete CASCADE | |||||
| * @var MinecraftServer | |||||
| */ | |||||
| public $ConcerningServer; | |||||
| /** | |||||
| * @DB-Relation | |||||
| * @Field ID | |||||
| * @FieldName UnlockedUserID | |||||
| * @ManyToOne | |||||
| * @OnUpdate CASCADE | |||||
| * @OnDelete CASCADE | |||||
| * @var MinecraftUser | |||||
| */ | |||||
| public $UnlockedUser; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name SubscriptionDate | |||||
| * @Default CURRENT_TIMESTAMP | |||||
| * @Type TIMESTAMP | |||||
| * @NotNull | |||||
| */ | |||||
| public $SubscriptionDate; | |||||
| } |
| <?php | |||||
| /** | |||||
| * @Name minecraft_user | |||||
| * @Unique Username | |||||
| */ | |||||
| class MinecraftUser extends Entity { | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name ID | |||||
| * @Type INT | |||||
| * @Primary | |||||
| * @AutoIncrement | |||||
| * @NotNull | |||||
| */ | |||||
| public $ID; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Username | |||||
| * @Type VARCHAR(256) | |||||
| * @NotNull | |||||
| * @Pattern /^[a-zA-Z0-9_]{3,16}$/ | |||||
| * @Pattern-Missmatch-Comment [ 'de' => 'Der Benutzername ist nur 3-16 Zeichen lang und enthält a-z, A-Z, 0-9, _', 'en' => 'The Username is only 3-16 chars long and contains only a-z, A-Z, 0-9, _' ] | |||||
| */ | |||||
| public $Username; | |||||
| /** | |||||
| * @DB-Relation | |||||
| * @Field ID | |||||
| * @FieldName SubscriptionID | |||||
| * @OneToMany | |||||
| * @OnUpdate CASCADE | |||||
| * @OnDelete CASCADE | |||||
| * @var MinecraftServer[] | |||||
| */ | |||||
| public $Subscriptions; | |||||
| /** | |||||
| * @DB-Relation | |||||
| * @Field ID | |||||
| * @FieldName OwnerID | |||||
| * @ManyToOne | |||||
| * @OnUpdate CASCADE | |||||
| * @OnDelete CASCADE | |||||
| * @var User | |||||
| */ | |||||
| public $Owner; | |||||
| public function HasSubscripted( MinecraftServer $server ) { | |||||
| $f = date( 'Y-m-01' ); $l = date( 'Y-m-t' ); | |||||
| $uid = $this->GetID(); | |||||
| $sid = $server->GetID(); | |||||
| $earlier = MinecraftServerSubscription::GetAll( "SubscriptionDate BETWEEN '$f' AND '$l' AND UnlockedUserID = $uid AND ConcerningServerID = $sid" ); | |||||
| return !!count( $earlier ); | |||||
| } | |||||
| } |
| <?php | |||||
| /** | |||||
| * @Name minecraft_user_account | |||||
| */ | |||||
| class MinecraftUserAccount extends Entity { | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name ID | |||||
| * @Type INT | |||||
| * @Primary | |||||
| * @AutoIncrement | |||||
| * @NotNull | |||||
| */ | |||||
| public $ID; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Modifier | |||||
| * @Type DECIMAL(10,2) | |||||
| * @NotNull | |||||
| */ | |||||
| public $Mod; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Comment | |||||
| * @Type TEXT | |||||
| */ | |||||
| public $Comment; | |||||
| /** | |||||
| * @DB-Relation | |||||
| * @Field ID | |||||
| * @FieldName DebtorID | |||||
| * @ManyToOne | |||||
| * @OnUpdate CASCADE | |||||
| * @OnDelete CASCADE | |||||
| * @var User | |||||
| */ | |||||
| public $Debtor; | |||||
| /** | |||||
| * @DB-Column | |||||
| * @Name Occurence | |||||
| * @Type TIMESTAMP | |||||
| * @Default CURRENT_TIMESTAMP | |||||
| * @NotNull | |||||
| */ | |||||
| public $Occurence; | |||||
| public static function ACCOUNT() { | |||||
| if ( User::ONLINE() ) return defaulted( MinecraftUserAccount::SUM( 'Modifier', [ 'DebtorID' => User::CURRENT()->ID ] ), '0' ); | |||||
| return '0'; | |||||
| } | |||||
| } |
| <meta log-in /> | |||||
| <div style="width: 100%; text-align: right; border: 1px solid white; border-radius: 1rem; padding: 1rem; margin: 1rem 0; box-sizing: border-box;"> | |||||
| <span>Account: <a eval-innerText="MinecraftUserAccount::ACCOUNT() . ' €'"></a></span> | |||||
| </div> |