HEX
Server: Apache/2.4.59 (Debian)
System: Linux keymana 4.19.0-21-cloud-amd64 #1 SMP Debian 4.19.249-2 (2022-06-30) x86_64
User: lijunjie (1003)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/uileague/wp-content/themes/uileague/helper/uileague_socket.php
<?php
class WebSocketHelper
{
    // 保存用户和socket之间的联系
    public static $pb_table = "orm_sock_fd";

    const TYPE_TEST = "test";
    const TYPE_ERROR = "error";
    const TYPE_LOGIN_ANOTHER_DEVICE = "loginOtherDevice";
    const TYPE_ONLINE_HEARTBEAT = "onlineHeartbeat";
    const TYPE_USER_UPDATE = "updaeUser";
    const TYPE_UPDATE_MATCH = "updateMatch";
    const TYPE_GET_MATCHES = "getMatches";
    const TYPE_GET_PLAYER_FIRST = "getPlayerFirst";
    const TYPE_GET_PLAYER_REPLACE = "getPlayerReplace";
    const TYPE_GET_REFEREES = "getReferees";
    const TYPE_GET_PLAYER_LIST = "getPlayerList";

    public static function set($uid, $wpuid, $fd, $isMobile = true)
    {
        $row = self::get_by_uid($uid, $wpuid);
        global $wpdb;
        if ($row != null) {
            if ($isMobile) {
                $res = $wpdb->update(
                    self::$pb_table,
                    array(
                        'fd' => $fd,
                        'updated' => current_time('mysql'),
                    ),
                    array('id' => $row->id),
                    array('%d', '%s'),
                    array('%d')
                );
            } else {
                $res = $wpdb->update(
                    self::$pb_table,
                    array(
                        'fd_web' => $fd,
                        'updated' => current_time('mysql'),
                    ),
                    array('id' => $row->id),
                    array('%d', '%s'),
                    array('%d')
                );
            }
        } else {
            $res = $wpdb->insert(
                self::$pb_table,
                array(
                    'uid' => $uid,
                    'wpuid' => $wpuid,
                    'fd' => $isMobile ? $fd : 0,
                    'fd_web' => $isMobile ? 0 : $fd,
                    'created' => current_time('mysql'),
                    'updated' => current_time('mysql'),
                ),
                array('%d', '%d', '%d', '%d', '%s', '%s')
            );
        }
        return $res !== false;
    }

    public static function reset_by_fd($fd)
    {
        $row = self::get_by_fd($fd);
        if ($row != null) {
            if ($fd == $row->fd) { // mobile
                $res = self::set($row->uid, $row->wpuid, 0, true);
            } else if ($fd == $row->fd_web) { // web
                $res = self::set($row->uid, $row->wpuid, 0, false);
            }
        } else {
            $res = true;
        }
        return $res !== false;
    }

    public static function get_by_uid($uid, $wpuid)
    {
        global $wpdb;
        return $wpdb->get_row($wpdb->prepare("select * from `" . self::$pb_table . "` where uid = %d and wpuid = %d", $uid, $wpuid));
    }

    public static function get_by_fd($fd)
    {
        global $wpdb;
        return $wpdb->get_row($wpdb->prepare("select * from `" . self::$pb_table . "` where fd = %d or fd_web = %d", $fd, $fd));
    }
}