Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pmmppluginsrepository/proxy-thread
Proxy with server socket handling
https://github.com/pmmppluginsrepository/proxy-thread
php pmmp pmmp-virion proxy proxy-thread skh6075
Last synced: 2 months ago
JSON representation
Proxy with server socket handling
- Host: GitHub
- URL: https://github.com/pmmppluginsrepository/proxy-thread
- Owner: PMMPPluginsRepository
- Created: 2022-10-04T11:58:53.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-05T12:59:42.000Z (over 2 years ago)
- Last Synced: 2024-10-09T23:04:15.766Z (3 months ago)
- Topics: php, pmmp, pmmp-virion, proxy, proxy-thread, skh6075
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# proxy-thread
Proxy with server socket handling## Usage
Connect when the plugin that will use the proxy is activated**NOTE:** If you try to call the class without the library loaded, you will get an error. After adding `DEVirion to depend`, call the proxy class in the `onEnable` method.
```php
protected function onEnable() : void{
$this->proxy = libProxyThread::createMultiProxy($this, $address ?? "127.0.0.1");
}
```## Register a Proxy Server
This proxy library can connect multiple servers**NOTE:** `receivePort` must not be duplicated, `sendPort` is the receivePort of another proxy server.
```php
$this->proxy->insert("lobby_multi_chat", new ProxyThread($this->multiProxy, 1000, (function(): Volatile{
$volatile = new Volatile();
$volatile[] = 1001; //skywars multi chat proxy port
return $volatile;
})()));
$this->proxy->insert("skywars_multi_chat", new ProxyThread($this->multiProxy, 1001, (function(): Volatile{
$volatile = new Volatile();
$volatile[] = 1000; //lobby multi chat proxy port
return $volatile;
})()));
```## Example Proxy Handling
When the chat is sent from the lobby server, it is also sent to the skywars server.**CHANNEL:** `lobby`
```php
public function onPlayerChatEvent(PlayerChatEvent $event): void{
if(!$event->isCancelled()){
$this->proxy->select("skywars_multi_chat")->send([
ProxyThread::KEY_IDENTIFY => "multi-chat",
ProxyThread::KEY_DATA => ["format" => $event->getFormat()]
]);
}
}
```
**CHANNEL:** `skywars`
```php
public function onProxyReceiveDataEvent(ProxyReceiveDataEvent $event): void{
$iterator = $event->getIterator();
if($iterator->offsetGet(ProxyThread::KEY_IDENTIFY) !== "multi-chat"){
return;
}
$data = $iterator->offsetGet(ProxyThread::KEY_DATA);
$this->getServer()->broadcastMessage($data["format"]);
}
```