chatserver.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. session_start();
  3. include_once("config.php");
  4. include("functions.php");
  5. include("bbcode.php");
  6. if (!isset($_SESSION['ssb-user']) && !isset($_SESSION['ssb-pass'])) { echo "ERROR: Not logged in!"; header("Location: index.php"); exit(1); }
  7. if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && !isset($_GET['friend'])){
  8. $nick = $_GET['nick'];
  9. $msg = bbcode_format(nl2br(htmlentities(stripcslashes($_GET['msg']))));
  10. $line = "<table><tr><td style='vertical-align: top;'><img class='avatar_chat' src='?do=avatarlocation&user=" . $nick . "' title='User Avatar'></td><td class='message'><b>$nick</b>: $msg</td></tr></table>\n";
  11. $old_content = file_get_contents($chat_db);
  12. $lines = count(file($chat_db));
  13. if($lines>$server_msgcount) {
  14. $old_content = implode("\n", array_slice(explode("\n", $old_content), 1));
  15. }
  16. file_put_contents($chat_db, $old_content.$line);
  17. echo $line;
  18. } else if (isset($_GET['msg']) && $_GET['msg']!="" && isset($_GET['nick']) && isset($_GET['friend'])){
  19. $friendNick = $_GET['friend'];
  20. $nick = $_SESSION['ssb-user'];
  21. $friendcount = file_get_contents("ssb_db/friends/" . $nick . ".count");
  22. include "ssb_db/friends/" . $nick . ".php";
  23. // Checking if you're friend
  24. for($x = 1; $x <= $friendcount; $x++)
  25. {
  26. if($friendNick == ${"friend" . $x}) {
  27. $msgCount = file_get_contents("ssb_db/friends/" . ${"friend_chat_db" . $x} . ".count");
  28. $msgCount = $msgCount + 1;
  29. $msg = bbcode_format(nl2br(htmlentities(stripcslashes($_GET['msg']))));
  30. $line_start = "<?php \$msg" . $msgCount . " = \"<table><tr><td style='vertical-align: top;'><img class='avatar_chat' src='?do=avatarlocation&user=" . $nick . "' title='User Avatar'></td><td class='message'><b>$nick</b>: $msg</td></tr></table>";
  31. $line_end = "\"; ?>\n";
  32. $old_content = file_get_contents("ssb_db/friends/" . ${"friend_chat_db" . $x} . ".php");
  33. $notifications = file_get_contents("ssb_db/friends/" . ${"friend" . $x} . ".notifications");
  34. // update conversation message count
  35. file_put_contents("ssb_db/friends/" . ${"friend_chat_db" . $x} . ".count", $msgCount);
  36. // conents into database
  37. file_put_contents("ssb_db/friends/" . ${"friend_chat_db" . $x} . ".php", $old_content . $line_start . $line_end);
  38. // notifications!
  39. file_put_contents("ssb_db/friends/" . ${"friend" . $x} . ".notifications", "<b>" . $nick . "</b> sent you a <a href='?do=privmsg&friend=" . $nick . "'>message</a>\n" . $notifications);
  40. }
  41. }
  42. } else if (isset($_GET['get'])){
  43. $friendNick = $_GET['get'];
  44. $nick = $_SESSION['ssb-user'];
  45. $friendcount = file_get_contents("ssb_db/friends/" . $nick . ".count");
  46. include "ssb_db/friends/" . $nick . ".php";
  47. for($x = 1; $x <= $friendcount; $x++)
  48. {
  49. if($friendNick == ${"friend" . $x}) {
  50. $msgCount = file_get_contents("ssb_db/friends/" . ${"friend_chat_db" . $x} . ".count");
  51. include "ssb_db/friends/" . ${"friend_chat_db" . $x} . ".php";
  52. for($y = 1; $y <= $msgCount; $y++) {
  53. echo ${"msg" . $y};
  54. }
  55. } //else { echo "Not friend!"; }
  56. //echo "Finding friend in slot " . $x;
  57. }
  58. } else if (isset($_GET['all'])) {
  59. //$content = file_get_contents($server_db);
  60. // This is faster
  61. $flag = file($chat_db);
  62. $content = "";
  63. foreach ($flag as $value) {
  64. $content .= $value;
  65. }
  66. echo $content;
  67. }/* else if(isset($_GET['ping'])) {
  68. $username = $_GET['nick'];
  69. } else if(isset($_GET['pong'])) {
  70. }*/
  71. ?>