Jump to content

TeamSpeak 3 Module (Alpha)


Paul

Recommended Posts

  • 8 months later...
  • 7 months later...

Cancellations typically remove the account from the service, so it would make sense for the canceled service to delete the server on Teamspeak. It doesn't look like the Teamspeak API supports any type of service suspension, so the module doesn't support suspensions in Blesta. What is the behavior you are expecting?

Link to comment
Share on other sites

6 hours ago, Tyson said:

Cancellations typically remove the account from the service, so it would make sense for the canceled service to delete the server on Teamspeak. It doesn't look like the Teamspeak API supports any type of service suspension, so the module doesn't support suspensions in Blesta. What is the behavior you are expecting?

Hello Tyson

Previously I used whmcs and when the service went into suspension, 2 things happened:
1.- Virtual server was stopped
2.- Auto-start function disabled, this in case vps was restarted  vitual server client did not start.

Link to comment
Share on other sites

Hello

I added functions to code of this module. Whit this code suspend and unsuspend works fine, please check it:

Teamspeak.php suspend function:

    public function suspendService($package, $service, $parent_package = null, $parent_service = null)
    {
        $row = $this->getModuleRow();
        $api = $this->getApi(
            $row->meta->hostname,
            $row->meta->username,
            $row->meta->password,
            $row->meta->port
        );

        if (!$row) {
            $this->Input->setErrors(
                ['module_row' => ['missing' => Language::_('Teamspeak.!error.module_row.missing', true)]]
            );

            return;
        }

        // Get service parameters
        $service_fields = $this->serviceFieldsToObject($service->fields);
        // Modify "virtualserver_autostart" to 0
        $this->parseResponse($api->suspendServer($service_fields->teamspeak_sid));
        // Stop server
        $this->parseResponse($api->stopServer($service_fields->teamspeak_sid));


        return null;
    }

Teamspeak.php unsuspend function:

    public function unsuspendService($package, $service, $parent_package = null, $parent_service = null)
    {
        $row = $this->getModuleRow();
        $api = $this->getApi(
            $row->meta->hostname,
            $row->meta->username,
            $row->meta->password,
            $row->meta->port
        );

        if (!$row) {
            $this->Input->setErrors(
                ['module_row' => ['missing' => Language::_('Teamspeak.!error.module_row.missing', true)]]
            );

            return;
        }

        // Get service parameters
        $service_fields = $this->serviceFieldsToObject($service->fields);
        // Modify "virtualserver_autostart" to 1
        $this->parseResponse($api->unsuspendServer($service_fields->teamspeak_sid));
        // Start server
        $this->parseResponse($api->startServer($service_fields->teamspeak_sid));


        return null;
    }

These codes call two new functions in teamspeak_api.php:

teamspeak_api.php suspendserver function:

    public function suspendServer($sid)
    {
        try {
            // Build the parameters array
            $api_params = [
                'virtualserver_autostart' => 0
            ];

            // Fetch the virtual server instance, and modify it
            $instance = $this->apiRequest('serverquery')->serverList()[$sid];
            $result = $instance->modify($api_params);

            // Add a control variable to know if the API request has been send successfully
            if (empty($result['error'])) {
                $result['status'] = true;
            }

        } catch (Exception $e) {
            $result = [
                'error' => $e->getMessage(),
                'status' => false,
                'code' => $e->getCode()
            ];
        }

        return (object) $result;
}

teamspeak_api.php unsuspendserver function:

    public function unsuspendServer($sid)
{
        try {
            // Build the parameters array
            $api_params = [
                'virtualserver_autostart' => 1
            ];

            // Fetch the virtual server instance, and modify it
            $instance = $this->apiRequest('serverquery')->serverList()[$sid];
            $result = $instance->modify($api_params);

            // Add a control variable to know if the API request has been send successfully
            if (empty($result['error'])) {
                $result['status'] = true;
            }

        } catch (Exception $e) {
            $result = [
            'error' => $e->getMessage(),
            'status' => false,
            'code' => $e->getCode()
            ];
        }

    return (object) $result;
}

That is all, i attached file if someone wants to donwnload it  

teamspeak.php teamspeak_api.php

Link to comment
Share on other sites

Do you have a link to their API documentation? If their system will observe that 'virtualserver_autostart' option and not let the user start a suspended server, then we can update the module to add service suspensions/unsuspensions as you have.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...