Advertisement
dcomicboy

chat?

Sep 5th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.64 KB | None | 0 0
  1. <?php
  2. if(isset($_GET["action"])){$action = $_GET["action"];
  3. }else{$action = "null";}
  4.  
  5. if(isset($_GET["password"])){$password = $_GET["password"];
  6. }
  7. if(isset($_GET["username"])){$username = $_GET["username"];
  8. }
  9. $conn = new mysqli("127.0.0.1", "root", "", "nitto");
  10. $date = date("Y-m-d H:i:s");
  11. if($action == "getRoomList"){
  12. //roomPassword1=0 means public
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. $resultGetRooms = $conn->query("SELECT * FROM rooms ORDER BY Perm,roomName ASC LIMIT 100");
  20. $i=0;
  21. while ($row = $resultGetRooms->fetch_assoc())
  22. {
  23. $i++;
  24. $roomID = $row["roomID"];
  25. $resultRoomCount = $conn->query("SELECT * FROM sessions WHERE roomID='$roomID'");
  26. $count1 = mysqli_num_rows($resultRoomCount);
  27. if($row['roomPassword'] != "")
  28. $password = "1";
  29. else
  30. $password = "0";
  31. print "roomName" .$i. "=" .$row["roomName"]. "&roomCount".$i."=" .$count1. "&roomID".$i."=".$row["roomID"]."&roomPassword".$i."=".$password."&";
  32.  
  33.  
  34. }
  35.  
  36.  
  37.  
  38.  
  39. }
  40.  
  41. if($action == "getRoomMessages"){
  42. if(isset($_GET["roomID"])){$roomID = $_GET["roomID"];}
  43. if(isset($_GET["userName"]))$userName = $_GET["userName"];
  44.  
  45.  
  46.  
  47.  
  48. //Update creation time because user is still in there and don't want it deleted.
  49. $conn->query("UPDATE rooms SET CreationTime='$date' WHERE roomID='$roomID'");
  50. //Check and delete unused user created rooms after 30 seconds if no users.
  51. $date2 = date('Y-m-d H:i:s', strtotime($date) - 30);//Check creation date vs 30 seconds ago.
  52. $conn->query("DELETE FROM rooms WHERE Perm='1' AND CreationTime < '$date2'");
  53. //Check and delete unused user created rooms after 30 seconds.^^
  54.  
  55. //roomPassword1=0 means public
  56.  
  57.  
  58. //Remove any user not in a room for 30 seconds.
  59.  
  60. $conn->query("UPDATE sessions SET roomID='0' WHERE DATETIME < '$date2'");
  61.  
  62. //Update chat whether this user is in a room or not.
  63.  
  64. $conn->query("UPDATE sessions SET roomID='$roomID', DATETIME='$date' WHERE Name='$userName'");
  65. //if this user does not exist in session table then we insert him. only once though.
  66. $result = $conn->query("SELECT * FROM sessions WHERE Name='$userName'");
  67. $count = mysqli_num_rows($result);
  68. if($count == 0){
  69. echo"asdf";
  70.  
  71. $conn->query("INSERT INTO sessions (IP, Session, Name, roomID, DATETIME, mute)
  72. VALUES ('', '', '$userName', '$roomCount', '$date', '0')");
  73.  
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. echo'newMessage=';
  81. $result = $conn->query("SELECT * FROM chatMessages WHERE roomID='$roomID' ORDER BY DATETIME LIMIT 30");
  82. while ($row = $result->fetch_assoc())
  83. {
  84. $name = $row["Name"];
  85. $resultCheckMute = $conn->query("SELECT * FROM sessions WHERE Name='$name' AND mute='1'");
  86. $count = mysqli_num_rows($resultCheckMute);
  87.  
  88.  
  89. if($count == "1" && $row["Name"] == $userName){
  90. print '<B>System->'.$row["Name"]. ': </B><font color="#cc99ff">You are still muted. Your messages will be recorded but not shown.</font><BR>';
  91. }
  92. else if($count == "1"){}
  93.  
  94. //possible mod color#0066ff.
  95.  
  96. else if($row["PLVL"] == "admin"){
  97. print '<B>'.$row["Name"]. ': </B><font color="#FFD700">' .$row["Message"]. '</font><BR>';
  98. }
  99. else if($row["PLVL"] == "system"){
  100. print '<B>'.$row["Name"]. ': </B><font color="#cc99ff">' .$row["Message"]. '</font><BR>';
  101. }
  102. else{
  103. print '<B>'.$row["Name"]. ': </B>' .$row["Message"]. '<BR>';}
  104.  
  105.  
  106.  
  107.  
  108. }
  109.  
  110. $result = $conn->query("SELECT * FROM chatMessages WHERE MessageTo='$userName' AND imRead='1' ORDER BY DATETIME LIMIT 30");
  111. $i=0;
  112. while ($row = $result->fetch_assoc())
  113. {
  114. $i++;
  115. if($row["PLVL"] == "admin"){
  116.  
  117. print '&instantMessageFrom' .$i. '='.$row["Name"]. '&instantMessageFromID' .$i. '=' .$row["Name"]. '&instantMessage' .$i. '=<font color="#FFD700">' .$row["Message"]. '</font>';
  118. }
  119. else{
  120. print '&instantMessageFrom' .$i. '='.$row["Name"]. '&instantMessageFromID' .$i. '=' .$row["Name"]. '&instantMessage' .$i. '='.$row["Message"];}
  121. $ID = $row["ID"];
  122. //mark im read
  123. $conn->query("UPDATE chatMessages SET imRead='0' WHERE MessageTo='$userName' AND ID='$ID'");
  124.  
  125. }
  126.  
  127.  
  128. }
  129.  
  130. if($action == "sendRoomMessage"){
  131. //NEEDS ADMIN PRIVS
  132.  
  133.  
  134. if(isset($_GET["roomID"]))
  135. $roomID = $_GET["roomID"];
  136. if(isset($_GET["userName"]))$username = $_GET["userName"];
  137.  
  138. if(isset($_GET["message"]))
  139. $message = $_GET["message"];
  140. if($username != "McBane"){$plvl = "user";}
  141. else{$plvl = "admin";
  142. $str = explode(' ', $message);
  143. $command = substr(strrchr($str[0], '/'), 1);
  144.  
  145. if (isset($str[1]))
  146. {
  147. if($str[0] == "/mute"){
  148. $message = $str[1]. " has been muted for 1 hour!";
  149. $username = "System";
  150. $plvl = "system";
  151. $conn->query("UPDATE sessions SET mute='1' WHERE Name='$str[1]'");
  152. }
  153. else if($str[0] == "/unmute"){
  154. $message = $str[1]. " has been unmuted!";
  155. $username = "System";
  156. $plvl = "system";
  157. $conn->query("UPDATE sessions SET mute='0' WHERE Name='$str[1]'");}
  158. }
  159.  
  160.  
  161. }
  162. /// needs a username and password check?
  163. $message = strip_tags($message);//remove html
  164. $conn->query("INSERT INTO chatMessages (ID, Name, PLVL, Message, DATETIME, roomID)
  165. VALUES ('', '$username', '$plvl', '$message', '$date', '$roomID')");
  166.  
  167.  
  168.  
  169. }
  170. if($action == "sendInstantMessage"){
  171. //NEEDS ADMIN PRIVS
  172.  
  173. if(isset($_GET["roomID"]))
  174. $roomID = $_GET["roomID"];
  175. if(isset($_GET["userName"]))$username = $_GET["userName"];
  176. if(isset($_GET["messageTo"]))$messageTo = $_GET["messageTo"];
  177. if(isset($_GET["messageFrom"]))$messageFrom = $_GET["messageFrom"];
  178.  
  179. if(isset($_GET["message"]))
  180. $message = $_GET["message"];
  181. if($messageFrom != "McBane"){$plvl = "user";}
  182. else{$plvl = "admin";}
  183.  
  184. /// needs username and password check
  185. $message = strip_tags($message);//remove html
  186. $conn->query("INSERT INTO chatMessages (ID, Name, PLVL, Message, DATETIME, roomID, imRead, MessageTo)
  187. VALUES ('', '$messageFrom', '$plvl', '$message', '$date', '$roomID', '1', '$messageTo')");
  188.  
  189.  
  190.  
  191. }
  192. if($action == "getRoomMembers"){
  193. //roomPassword1=0 means public
  194. if(isset($_GET["roomID"])){$roomID = $_GET["roomID"];}
  195.  
  196. //echo"userName1=Admin&status1=0&clickable1=1&type=admin&accountID1=1&memberLevel1=0";
  197. $result = $conn->query("SELECT * FROM sessions WHERE roomID='$roomID' ORDER BY NAME ASC LIMIT 100");
  198. $i=0;
  199. while ($row = $result->fetch_assoc())
  200. {
  201. $i++;
  202. if($row["Name"] == "McBane"){$plvl = "admin";$m = "1";}
  203. else{$plvl = "user"; $m = "0";}
  204.  
  205. print "userName" .$i. "=" .$row["Name"]. "&status" .$i. "=0&clickable" .$i. "=1&type" .$i. "=" .$plvl. "&accountID" .$i. "=" .$row["Name"]. "&memberLevel" .$i. "=".$m."&";
  206.  
  207.  
  208. }
  209. echo"&roomNumber=" .$i;
  210.  
  211. }
  212.  
  213. if($action == "checkRoomPassword"){
  214.  
  215. if(isset($_GET["roomID"])){$roomID = $_GET["roomID"];}
  216. if(isset($_GET["roomPassword"])){$roomPassword = $_GET["roomPassword"];}
  217.  
  218.  
  219. $result = $conn->query("SELECT * FROM rooms WHERE roomID='$roomID' AND roomPassword='$roomPassword'");
  220. $count = mysqli_num_rows($result);
  221.  
  222. if($count == 1){
  223.  
  224. echo"status=1";
  225.  
  226. }
  227. else{echo"status=0";}
  228.  
  229. }
  230. if($action == "createRoom"){
  231.  
  232. if(isset($_GET["roomName"])){$roomName = $_GET["roomName"];}
  233. if(isset($_GET["roomPassword"])){$roomPassword = $_GET["roomPassword"];}
  234.  
  235.  
  236. $result = $conn->query("SELECT * FROM rooms WHERE roomName='$roomName'");
  237. $count = mysqli_num_rows($result);
  238.  
  239. if($count == 1){
  240.  
  241. echo"status=0";
  242.  
  243. }
  244. else{
  245. //NEEDS ADMIN PRIVS TO SKIP PASSWORD
  246. //Perm = 1 means user created room. 0 means static room.
  247.  
  248. $sqlCreate = "INSERT INTO rooms (roomName, Perm, CreationTime, roomPassword)
  249. VALUES ('$roomName', '1', '$date', '$roomPassword')";
  250. if ($conn->query($sqlCreate) === TRUE) {
  251. $last_id = $conn->insert_id;
  252. echo"status=1&roomID=" .$last_id;
  253.  
  254. }
  255. else{
  256. echo"status=0";}
  257.  
  258.  
  259. }
  260.  
  261. }
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement