Skip to first unread message

D

unread,
Sep 18, 2016, 10:22:16 PM9/18/16
to ajax...@googlegroups.com
Hi,
I was editing my customAJAX chat file to add new commands. I get the white screen alot but I always seem to fix my errors but this white screen won't seem to go. 
Can you guys check my script to see if theres any errors. ( was editing near the bottom when it happened )
Thanks

P.S Im trying out the code input formatting, hopefully the code comes out right. :)

<?php
/*
 * @package AJAX_Chat
 * @author Sebastian Tschan
 * @copyright (c) Sebastian Tschan
 * @license Modified MIT License
 */

class CustomAJAXChat extends AJAXChat {

// Returns an associative array containing userName, userID and userRole
// Returns null if login is invalid
function getValidLoginUserData() {
$customUsers = $this->getCustomUsers();
if($this->getRequestVar('password')) {
// Check if we have a valid registered user:

$userName = $this->getRequestVar('userName');
$userName = $this->convertEncoding($userName, $this->getConfig('contentEncoding'), $this->getConfig('sourceEncoding'));

$password = $this->getRequestVar('password');
$password = $this->convertEncoding($password, $this->getConfig('contentEncoding'), $this->getConfig('sourceEncoding'));

foreach($customUsers as $key=>$value) {
if(($value['userName'] == $userName) && ($value['password'] == $password)) {
$userData = array();
$userData['userID'] = $key;
$userData['userName'] = $this->trimUserName($value['userName']);
$userData['userRole'] = $value['userRole'];
return $userData;
}
}
return null;
} else {
// Guest users:
return $this->getGuestUser();
}
}

// Store the channels the current user has access to
// Make sure channel names don't contain any whitespace
function &getChannels() {
if($this->_channels === null) {
$this->_channels = array();
$customUsers = $this->getCustomUsers();
// Get the channels, the user has access to:
if($this->getUserRole() == AJAX_CHAT_GUEST) {
$validChannels = $customUsers[0]['channels'];
} else {
$validChannels = $customUsers[$this->getUserID()]['channels'];
}
// Add the valid channels to the channel list (the defaultChannelID is always valid):
foreach($this->getAllChannels() as $key=>$value) {
if ($value == $this->getConfig('defaultChannelID')) {
$this->_channels[$key] = $value;
continue;
}
// Check if we have to limit the available channels:
if($this->getConfig('limitChannelList') && !in_array($value, $this->getConfig('limitChannelList'))) {
continue;
}
if(in_array($value, $validChannels)) {
$this->_channels[$key] = $value;
}
}
}
return $this->_channels;
}

// Store all existing channels
// Make sure channel names don't contain any whitespace
function &getAllChannels() {
if($this->_allChannels === null) {
// Get all existing channels:
$customChannels = $this->getCustomChannels();
$defaultChannelFound = false;
foreach($customChannels as $name=>$id) {
$this->_allChannels[$this->trimChannelName($name)] = $id;
if($id == $this->getConfig('defaultChannelID')) {
$defaultChannelFound = true;
}
}
if(!$defaultChannelFound) {
// Add the default channel as first array element to the channel list
// First remove it in case it appeard under a different ID
unset($this->_allChannels[$this->getConfig('defaultChannelName')]);
$this->_allChannels = array_merge(
array(
$this->trimChannelName($this->getConfig('defaultChannelName'))=>$this->getConfig('defaultChannelID')
),
$this->_allChannels
);
}
}
return $this->_allChannels;
}

function &getCustomUsers() {
// List containing the registered chat users:
$users = null;
require(AJAX_CHAT_PATH.'lib/data/users.php');
return $users;
}
function getCustomChannels() {
// List containing the custom channels:
$channels = null;
require(AJAX_CHAT_PATH.'lib/data/channels.php');
// Channel array structure should be:
// ChannelName => ChannelID
return array_flip($channels);
}

//NEW STUFF IVE ADDED

    // This is where we can start adding custom commands
    function parseCustomCommands($text, $textParts) {
        switch($textParts[0]) {
        // Away from keyboard message:
        case '/away':
            $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' has set their status to Away');
            $this->setUserName($this->getLoginUserName().'[Away]');
            $this->updateOnlineList();
            $this->addInfoMessage($this->getUserName(), 'userName');
            return true;
        case '/online':
        case '/back':
            $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' has set their status to Online');
            $this->setUserName($this->getLoginUserName());
            $this->updateOnlineList();
            $this->addInfoMessage($this->getUserName(), 'userName');
            return true;
        case '/trout':
        case '/slap':
        $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' slaps '.implode(' ', array_slice($textParts, 1)).' with a wet trout');
            return true;
        case '/status':
            $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' has set their status to '.implode(' ', array_slice($textParts, 1)));
            $this->setUserName($this->getLoginUserName().'['.implode(' ', array_slice($textParts, 1)).']');
            $this->updateOnlineList();
            $this->addInfoMessage($this->getUserName(), 'userName');
            return true;

//MY PERSONAL COMMANDS:
  case '/milestone':
        case '/achievement':
        $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' has reached '.implode(' ', array_slice($textParts, 1)).' LEVEL UP!!!');
            return true;
case '/shark':
        $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' commands a shark to eat '.implode(' ', array_slice($textParts, 1)).' ... press F to pay respects');
            return true;
        case '/party':
        $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().'  '.implode(' ', array_slice($textParts, 1)).' Lets party!!! ');
            return true;
case '/partytime':
        $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().'  '.implode(' ', array_slice($textParts, 1)).' Party Time!!! ');
            return true;
        
        } // End of switch
    } // End of parseCustomCommands



Banjo Fox

unread,
Sep 19, 2016, 10:46:06 AM9/19/16
to ajax...@googlegroups.com
D,
I was able to add your new commands without getting any screen errors HOWEVER...
your /shark command is broken ;)

If the output you want is:
/shark spoonman
(10:35:43) ChatBot: user commands a shark to eat spoonman...press F to pay respects

then you need to remove the whitespace surrounding the ellipsis which is a a PHP parser token (apparently) http://php.net/manual/en/functions.arguments.php#functions.variable-arg-list.new

case '/shark':
        $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' commands a shark to eat '.implode(' ', array_slice($textParts, 1)).'...press F to pay respects');

Alternatively... if you wanted to keep the whitespace you need to wrap the text in double quotes so that the system prints out the ellipsis as regular text.


case '/shark':
        $this->insertChatBotMessage($this->getChannel(), $this->getLoginUserName().' commands a shark to eat '.implode(' ', array_slice($textParts, 1))." ... press F to pay respects");


D

unread,
Sep 19, 2016, 6:55:53 PM9/19/16
to AJAX-chat
Hi,
Thanks for the command fixes however The chat is still blank.

Banjo Fox

unread,
Sep 20, 2016, 10:14:17 AM9/20/16
to AJAX-chat
D,

It looks like the login page for your chat is the thing that isn't rendering.
Do you have a list of changes that you made?
Did you modify anything in lib/template/loggedOut.html?

It might be easier if you sent a zipped copy of your code (feel free to remove passwords).
Either that or we can discuss in my chat space

http://testing.blackcitygames.com/testing/chat-dev/

D

unread,
Sep 22, 2016, 5:57:21 AM9/22/16
to AJAX-chat
Hi,
I sent you a zipped copy recently. Hope to hear back soon. Thanks for your help.

D

unread,
Sep 23, 2016, 7:21:31 AM9/23/16
to AJAX-chat
Hi,
Have you had a chance to look at the code yet?
Reply all
Reply to author
Forward
0 new messages