Show DevBest talkietalkie - MySQLi based chat

Hindi

System.out.println(" ");
Dec 30, 2012
989
192
Do you have Java script enabled?
It works 100% for me, so I'm not sure what you've changed.
Yep I do have JS enabled, And haven't really changed anything yet. :p I'll try to make another account and make it admin and test?
 

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
@Macemore
How do I create my own commands? Such as
/commands - which shows the commands list
/ban <user> - Which Bans the user
in post.php there's two commands already in there (Current released version).
What I do is I copy one already made, the version I have on my pc has more commands, I'll link that in the bottom.
PHP:
  if (substr($message, 0, 1) == '/' && substr($message, 1) == 'clear') {
  if ($rank == 1) {
  $mysqli->query("TRUNCATE TABLE messages");
  } else {
  return false;
  }
  }
That's your standard clear command
if you don't understand php very well I'm not going to make a tutorial for that too, lrn2php on google.
$message is the message the user tried to send, the if statement gets $message's first character (a b ? etc.) and checks
if it's a "/", standard for commands but you can use anything you want. I suggest you learn substr for more advanced commands (ones with more variables).

The ban command I made basically changed the users rank to 2, in the database rank value can be 0, or a 1, 1 being admin. I changed the table so that 2 is banned (it would be better to have 0 as banned 1 as user and 2 as admin).
PHP:
  if (substr($message, 0, 1) == '/' && substr($message, 1, 3) == 'ban') {
  if ($rank == 1) {
  $variables = explode(" ", $message);
  $username  = substr($variables[1], 0);
       $username1 = 'Server';
       $thepost = "{$username} has been banned";

  $mysqli->query("UPDATE `users` SET rank='2' WHERE username = '{$username}'");
       $mysqli->query("INSERT INTO `messages` (user, message, timestamp) VALUES ('$username1', '$thepost', '$time')");
  } else {
  return false;
  }
  }
   
   //unban (literally the opposite of the obove)
  if (substr($message, 0, 1) == '/' && substr($message, 1, 5) == 'unban') {
  if ($rank == 1) {
  $variables = explode(" ", $message);
  $username  = substr($variables[1], 0);
       $username1 = 'Server';
       $thepost = "{$username} has been unbanned";

  $mysqli->query("UPDATE `users` SET rank='0' WHERE username = '{$username}'");
       $mysqli->query("INSERT INTO `messages` (user, message, timestamp) VALUES ('$username1', '$thepost', '$time')");
  } else {
  return false;
  }
  }
Here's the current running version on gamma.mace.pw:


Here's an example configuration for /commands to list all commands
PHP:
  if (substr($message, 0, 1) == '/' && substr($message, 1, 8) == 'commands') {
     $nm = "Available commands:\n
        +1 [user] - adds one to a user\n
        -1 [user] - removes one from a user\n
        /op [user] - makes a user admin \n
        /clear - removes all messages\n
        /color [user] #[color] - changes a user's color\n
        /mfw [link to image] [words] - does 4chan style mfw\n
        >[words] - 4chan green text\n";
        $user = 'Server';
        $mysqli->query("INSERT INTO `messages` (user, message, timestamp) VALUES ('$user', '$message', '$time')");
   }
inside the quotes from "Available" to "green text\n" you can add any commands you've made yourself using \n to make a new line.
I haven't tested this.
 

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
@Macemore the download link doesn't work. But I will try and integrate the commands into the version I have
Yeah something with sharefast @RastaLulz sharefast doesnt download on

if that doesn't work right click -> save link as,
if that doesn't work your browser is efukt
 

Jian

Resident Weeb
Contributor
Sep 2, 2011
687
437
in post.php there's two commands already in there (Current released version).
What I do is I copy one already made, the version I have on my pc has more commands, I'll link that in the bottom.
PHP:
  if (substr($message, 0, 1) == '/' && substr($message, 1) == 'clear') {
  if ($rank == 1) {
  $mysqli->query("TRUNCATE TABLE messages");
  } else {
  return false;
  }
  }
That's your standard clear command
if you don't understand php very well I'm not going to make a tutorial for that too, lrn2php on google.
$message is the message the user tried to send, the if statement gets $message's first character (a b ? etc.) and checks
if it's a "/", standard for commands but you can use anything you want. I suggest you learn substr for more advanced commands (ones with more variables).

The ban command I made basically changed the users rank to 2, in the database rank value can be 0, or a 1, 1 being admin. I changed the table so that 2 is banned (it would be better to have 0 as banned 1 as user and 2 as admin).
PHP:
  if (substr($message, 0, 1) == '/' && substr($message, 1, 3) == 'ban') {
  if ($rank == 1) {
  $variables = explode(" ", $message);
  $username  = substr($variables[1], 0);
       $username1 = 'Server';
       $thepost = "{$username} has been banned";

  $mysqli->query("UPDATE `users` SET rank='2' WHERE username = '{$username}'");
       $mysqli->query("INSERT INTO `messages` (user, message, timestamp) VALUES ('$username1', '$thepost', '$time')");
  } else {
  return false;
  }
  }
  
   //unban (literally the opposite of the obove)
  if (substr($message, 0, 1) == '/' && substr($message, 1, 5) == 'unban') {
  if ($rank == 1) {
  $variables = explode(" ", $message);
  $username  = substr($variables[1], 0);
       $username1 = 'Server';
       $thepost = "{$username} has been unbanned";

  $mysqli->query("UPDATE `users` SET rank='0' WHERE username = '{$username}'");
       $mysqli->query("INSERT INTO `messages` (user, message, timestamp) VALUES ('$username1', '$thepost', '$time')");
  } else {
  return false;
  }
  }
Here's the current running version on gamma.mace.pw:


Here's an example configuration for /commands to list all commands
PHP:
  if (substr($message, 0, 1) == '/' && substr($message, 1, 8) == 'commands') {
     $nm = "Available commands:\n
        +1 [user] - adds one to a user\n
        -1 [user] - removes one from a user\n
        /op [user] - makes a user admin \n
        /clear - removes all messages\n
        /color [user] #[color] - changes a user's color\n
        /mfw [link to image] [words] - does 4chan style mfw\n
        >[words] - 4chan green text\n";
        $user = 'Server';
        $mysqli->query("INSERT INTO `messages` (user, message, timestamp) VALUES ('$user', '$message', '$time')");
   }
inside the quotes from "Available" to "green text\n" you can add any commands you've made yourself using \n to make a new line.
I haven't tested this.
You can try the sscanf() function for the commands, its more efficient. Check the documentation if you're interested.
 

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
You can try the sscanf() function for the commands, its more efficient. Check the documentation if you're interested.
Looks good, I think I might update the version I have with this and release it as the final version.

Thanks!
 

Sysode

Front-End Developer
Dec 11, 2012
1,673
848
Looking forward to the final version. I'll prolly download it then, have a play around then leave it - worth it tho, ey? Nice work.
 

Users who are viewing this thread

Top