Jump to content

Recommended Posts

I know I'm a noob at php, but I know what all the functions do and I understand how this function works, but I can't figure out the cause of this error message I'm getting.

Running this in the console, I get PHP Notice: undefined offset on lines 215, 250, 251, and 252.

[code]<?php
function parse_buffer()
{

/*
:username!~identd@hostname JOIN :#php
:username!~identd@hostname PRIVMSG #PHP :action text
:username!~identd@hostname command channel :text
*/

global $con, $CONFIG;

$buffer = $con['buffer']['all'];
$buffer = explode(" ", $buffer, 4);

  $buffer['all'] = $con['buffer']['all']; //fix undefined key error
/* Get username */
$buffer['username'] = substr($buffer[0], 1, strpos($buffer['0'], "!")-1);

/* Get identd */
$posExcl = strpos($buffer[0], "!");
$posAt = strpos($buffer[0], "@");
$buffer['identd'] = substr($buffer[0], $posExcl+1, $posAt-$posExcl-1);
$buffer['hostname'] = substr($buffer[0], strpos($buffer[0], "@")+1);

/* The user and the host, the whole shabang */
$buffer['user_host'] = substr($buffer[0],1);

/* Isolate the command the user is sending from
the "general" text that is sent to the channel
This is  privmsg to the channel we are talking about.

We also format $buffer['text'] so that it can be logged nicely.
*/
switch (strtoupper($buffer[1])) //line 215
{
case "JOIN":
  $buffer['text'] = "*JOINS: ". $buffer['username']." ( ".$buffer['user_host']." )";
$buffer['command'] = "JOIN";
$buffer['channel'] = $CONFIG['channel'];
  break;
case "QUIT":
  $buffer['text'] = "*QUITS: ". $buffer['username']." ( ".$buffer['user_host']." )";
$buffer['command'] = "QUIT";
$buffer['channel'] = $CONFIG['channel'];
  break;
case "NOTICE":
  $buffer['text'] = "*NOTICE: ". $buffer['username'];
$buffer['command'] = "NOTICE";
$buffer['channel'] = substr($buffer[2], 1);
  break;
case "PART":
  $buffer['text'] = "*PARTS: ". $buffer['username']." ( ".$buffer['user_host']." )";
$buffer['command'] = "PART";
$buffer['channel'] = $CONFIG['channel'];
  break;
case "MODE":
  $buffer['text'] = $buffer['username']." sets mode: ".$buffer[3];
$buffer['command'] = "MODE";
$buffer['channel'] = $buffer[2];
break;
case "NICK":
$buffer['text'] = "*NICK: ".$buffer['username']." => ".substr($buffer[2], 1)." ( ".$buffer['user_host']." )";
$buffer['command'] = "NICK";
$buffer['channel'] = $CONFIG['channel'];
break;

default:
// it is probably a PRIVMSG
$buffer['command'] = $buffer[1]; //line 250
$buffer['channel'] = $buffer[2]; //line 251
$buffer['text'] = substr($buffer[3], 1); //line 252
break;
}
$con['buffer'] = $buffer;
}
?>[/code]

I assume it means that it can't find $buffer[1] $buffer[2] and $buffer[3], but my (limited) understanding tells me that they should be left over from the explode(" ", $buffer, 4) at the beginning of the function.
Link to comment
https://forums.phpfreaks.com/topic/32907-solved-help-with-irc-bot-script/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.