chatserver.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. $friendNick = $_GET['friend'];
  9. $nick = $_SESSION['ssb-user'];
  10. $friendcount = file_get_contents("ssb_db/friends/" . $nick . ".count");
  11. include "ssb_db/friends/" . $nick . ".php";
  12. // Checking if you're friend
  13. for($x = 1; $x <= $friendcount; $x++)
  14. {
  15. if($friendNick == ${"friend" . $x}) {
  16. $msgCount = file_get_contents("ssb_db/friends/" . ${"friend_chat_db" . $x} . ".count");
  17. $msgCount = $msgCount + 1;
  18. $msg = bbcode_format(nl2br(htmlentities(stripcslashes($_GET['msg']))));
  19. $line_start = "<?php \$msg" . $msgCount . " = \"<table><tr><td style='vertical-align: top;'><img class='avatar_chat' src='index.php?do=avatarlocation&user=" . $nick . "' title='User Avatar'></td><td class='message'><b>$nick</b>: $msg</td></tr></table>";
  20. $line_end = "\"; ?>\n";
  21. $old_content = file_get_contents("ssb_db/friends/" . ${"friend_chat_db" . $x} . ".php");
  22. $notifications = file_get_contents("ssb_db/friends/" . ${"friend" . $x} . ".notifications");
  23. // update conversation message count
  24. file_put_contents("ssb_db/friends/" . ${"friend_chat_db" . $x} . ".count", $msgCount);
  25. // conents into database
  26. file_put_contents("ssb_db/friends/" . ${"friend_chat_db" . $x} . ".php", $old_content . $line_start . $line_end);
  27. // notifications!
  28. 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);
  29. }
  30. }
  31. } else if (isset($_GET['get'])){
  32. $friendNick = $_GET['get'];
  33. $nick = $_SESSION['ssb-user'];
  34. $friendcount = file_get_contents("ssb_db/friends/" . $nick . ".count");
  35. include "ssb_db/friends/" . $nick . ".php";
  36. for($x = 1; $x <= $friendcount; $x++)
  37. {
  38. if($friendNick == ${"friend" . $x}) {
  39. $msgCount = file_get_contents("ssb_db/friends/" . ${"friend_chat_db" . $x} . ".count");
  40. include "ssb_db/friends/" . ${"friend_chat_db" . $x} . ".php";
  41. for($y = 1; $y <= $msgCount; $y++) {
  42. echo ${"msg" . $y};
  43. }
  44. } //else { echo "Not friend!"; }
  45. //echo "Finding friend in slot " . $x;
  46. }
  47. }
  48. ?>