TrackManiaControl/application/libs/FML/ManiaCode/JoinServer.php

84 lines
1.9 KiB
PHP
Raw Normal View History

2014-01-12 00:51:46 +01:00
<?php
namespace FML\ManiaCode;
/**
2014-06-21 03:18:21 +02:00
* ManiaCode Element for joining a server
2014-01-12 00:51:46 +01:00
*
2014-05-20 15:44:45 +02:00
* @author steeffeen <mail@steeffeen.com>
2014-04-13 18:21:40 +02:00
* @copyright FancyManiaLinks Copyright © 2014 Steffen Schröder
2014-05-18 19:45:50 +02:00
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
2014-01-12 00:51:46 +01:00
*/
2014-07-03 22:34:47 +02:00
class JoinServer extends Element {
2014-01-21 20:30:40 +01:00
/*
2014-06-21 03:18:21 +02:00
* Protected properties
2014-01-12 00:51:46 +01:00
*/
protected $tagName = 'join_server';
2014-06-21 03:18:21 +02:00
protected $login = null;
protected $serverIp = null;
protected $serverPort = null;
2014-01-12 00:51:46 +01:00
2014-01-19 19:30:21 +01:00
/**
2014-06-21 03:18:21 +02:00
* Create a new JoinServer object
2014-01-19 19:30:21 +01:00
*
2014-06-21 03:18:21 +02:00
* @param string $login (optional) Server login
2014-07-03 22:34:47 +02:00
* @return static
2014-01-19 19:30:21 +01:00
*/
public static function create($login = null) {
2014-06-21 03:18:21 +02:00
return new static($login);
2014-01-19 19:30:21 +01:00
}
2014-01-12 00:51:46 +01:00
/**
2014-06-21 03:18:21 +02:00
* Construct a new JoinServer object
2014-01-12 00:51:46 +01:00
*
2014-06-21 03:18:21 +02:00
* @param string $login (optional) Server login
2014-01-12 00:51:46 +01:00
*/
public function __construct($login = null) {
2014-08-11 23:15:53 +02:00
if ($login !== null) {
2014-01-12 00:51:46 +01:00
$this->setLogin($login);
}
}
/**
2014-06-21 03:18:21 +02:00
* Set the server login
2014-01-12 00:51:46 +01:00
*
2014-06-21 03:18:21 +02:00
* @param string $login Server login
2014-07-03 22:34:47 +02:00
* @return static
2014-01-12 00:51:46 +01:00
*/
public function setLogin($login) {
2014-06-21 03:18:21 +02:00
$this->login = (string)$login;
$this->serverIp = null;
$this->serverPort = null;
2014-01-12 00:51:46 +01:00
return $this;
}
/**
2014-06-21 03:18:21 +02:00
* Set the server ip and port
2014-01-12 00:51:46 +01:00
*
2014-06-21 03:18:21 +02:00
* @param string $serverIp Server ip
* @param int $serverPort Server port
2014-07-03 22:34:47 +02:00
* @return static
2014-01-12 00:51:46 +01:00
*/
2014-06-21 03:18:21 +02:00
public function setIp($serverIp, $serverPort) {
$this->serverIp = (string)$serverIp;
$this->serverPort = (int)$serverPort;
$this->login = null;
2014-01-12 00:51:46 +01:00
return $this;
}
/**
* @see \FML\ManiaCode\Element::render()
*/
public function render(\DOMDocument $domDocument) {
2014-07-03 22:34:47 +02:00
$xmlElement = parent::render($domDocument);
2014-08-11 23:15:53 +02:00
if ($this->serverIp === null) {
2014-01-12 00:51:46 +01:00
$loginElement = $domDocument->createElement('login', $this->login);
$xmlElement->appendChild($loginElement);
2014-05-18 19:45:50 +02:00
} else {
2014-06-21 03:18:21 +02:00
$ipElement = $domDocument->createElement('ip', $this->serverIp . ':' . $this->serverPort);
2014-01-12 00:51:46 +01:00
$xmlElement->appendChild($ipElement);
}
return $xmlElement;
}
}