Updated to newer Ratchet and also fixed some explosions.

This commit is contained in:
flash 2023-12-02 03:07:27 +00:00
parent c1710d2c2b
commit 4dce69a63b
6 changed files with 817 additions and 434 deletions

View file

@ -1,5 +1,8 @@
{
"require": {
"cboden/ratchet": "0.3.*"
"cboden/ratchet": "^0.4.4"
},
"require-dev": {
"phpstan/phpstan": "^1.10"
}
}

1207
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -236,7 +236,7 @@ class Database {
Database::$statements["logstore"]["uname"] = $user->username;
Database::$statements["logstore"]["color"] = $user->color;
Database::$statements["logstore"]["chan"] = $chan == null ? $user->channel : $chan;
Database::$statements["logstore"]["chrank"] = $chan[0] == "@" ? 0 : Context::GetChannel($user->channel)->permissionLevel;
Database::$statements["logstore"]["chrank"] = $chan[0] == "@" ? 0 : Context::GetChannel($user->channel)->permissionLevel ?? 0;
Database::$statements["logstore"]["msg"] = $msg;
Database::$statements["logstore"]["flags"] = substr($flags, 0, 4) ."0";
Database::Execute("logstore");

View file

@ -10,13 +10,14 @@ class Modules {
$mods = glob("./mods/*", GLOB_ONLYDIR);
foreach($mods as $mod) {
$name = substr($mod, strrpos($mod, "/")+1);
if(file_exists("{$mod}/{$name}.php")) {
include("{$mod}/{$name}.php");
if(class_exists("\\sockchat\\mods\\{$name}\\Main")) {
$fileName = "{$mod}/{$name}.php";
if(file_exists($fileName)) {
include($fileName);
$className = "\\sockchat\\mods\\{$name}\\Main";
if(class_exists($className)) {
Modules::$mods[$name] = $name;
$cmds = call_user_func_array("\\sockchat\\mods\\{$name}\\Main::Init", []);
$cmds = call_user_func_array("\\sockchat\\mods\\{$name}\\Main::GetCommands", []);
call_user_func([$className, 'Init']);
$cmds = call_user_func([$className, 'GetCommands']);
foreach($cmds as $cmd) {
if(array_key_exists($cmd, self::$cmds))
echo "Error loading module $name: Command $cmd has already been defined by module ". self::$cmds[$cmd] ."!\n";

View file

@ -1,6 +1,6 @@
<?php
namespace sockchat\mods\core;
use \sockchat\mods\GenericMod;
use \sockchat\Context;
@ -402,7 +402,7 @@ class Main extends GenericMod {
}
}
public static function OnCommandReceive($user, &$cmd, &$args) {
public static function OnCommandReceive($user, $cmd, $args) {
/*if(!self::IsSilenced($user) || (self::IsSilenced($user) && in_array($cmd, self::$allowedCmds))) {
if($cmd == "afk") {
$val = isset($args[0]) ? strtoupper(mb_substr($args[0], 0, self::$maxAfkTagLength)) : "AFK";

View file

@ -37,12 +37,12 @@ class Chat implements MessageComponentInterface {
}
public function onOpen(ConnectionInterface $conn) {
$conn->remoteAddress = $conn->WebSocket->request->getHeader('X-Real-IP') ?? $conn->remoteAddress;
$conn->remoteAddress = $conn->httpRequest->getHeader('X-Real-IP')[0] ?? $conn->remoteAddress;
Context::CheckPings();
}
public function onMessage(ConnectionInterface $conn, $msg) {
$conn->remoteAddress = $conn->WebSocket->request->getHeader('X-Real-IP') ?? $conn->remoteAddress;
$conn->remoteAddress = $conn->httpRequest->getHeader('X-Real-IP')[0] ?? $conn->remoteAddress;
Context::CheckPings();
if(true) {
$parts = explode(Utils::$separator, $msg);
@ -128,7 +128,7 @@ class Chat implements MessageComponentInterface {
}
public function onClose(ConnectionInterface $conn) {
$conn->remoteAddress = $conn->WebSocket->request->getHeader('X-Real-IP') ?? $conn->remoteAddress;
$conn->remoteAddress = $conn->httpRequest->getHeader('X-Real-IP')[0] ?? $conn->remoteAddress;
echo $conn->remoteAddress ." has disconnected\n";
foreach(Context::$onlineUsers as $user) {
if($user->sock == $conn) {
@ -141,7 +141,7 @@ class Chat implements MessageComponentInterface {
}
public function onError(ConnectionInterface $conn, \Exception $err) {
$conn->remoteAddress = $conn->WebSocket->request->getHeader('X-Real-IP') ?? $conn->remoteAddress;
$conn->remoteAddress = $conn->httpRequest->getHeader('X-Real-IP')[0] ?? $conn->remoteAddress;
Context::CheckPings();
echo "Error on ". $conn->remoteAddress .": ". $err ."\n";
}