관리 메뉴

ㄴrㅎnㅂrㄹrㄱi

AHK Chat (Another Method) 본문

AUTOHOTKEY/스크립트

AHK Chat (Another Method)

님투 2007. 11. 25. 11:17
반응형

AHK Chat (Another Method)


AHK

  1. #Persistent
  2. start:
  3. Gui, Add, Edit, x76 y10 w100 h20 vusername ,
  4. Gui, Add, Text, x6 y10 w70 h20 , User Name:
  5. Gui, Add, Button, x43 y40 w100 h30 glogin +default, Login
  6. Gui, Show, h83 w188, Login
  7. Return
  8.  
  9. login:
  10. gui submit
  11. gui destroy
  12. URLDownloadToFile, http://jon2s.com/ahkchat/chat.php?event=login&loggedusername=%username%, %A_Temp%\login.txt
  13. FileReadLine, loginresult, %A_Temp%\login.txt, 1
  14. if loginresult = success
  15. {
  16.   URLDownloadToFile, http://jon2s.com/ahkchat/chat.php?event=userlist, %A_Temp%\userlist.txt
  17.   URLDownloadToFile, http://jon2s.com/ahkchat/chat.php?event=chat&loggedusername=%username%, %A_Temp%\chat.txt
  18.   FileReadLine, userlist, %A_Temp%\userlist.txt, 1
  19.   StringReplace, userlist, userlist, &(), `n, 1
  20.   FileReadLine, chat, %A_Temp%\chat.txt, 1
  21.   StringReplace, chat, chat, &(), `n, 1
  22.   SetTimer, updatechat, 5000
  23.   goto displaychat
  24. }
  25. if loginresult <> success
  26. {
  27.   msgbox,,Warning, There was a problem logging in.  Please try again.
  28.   goto start
  29. }
  30.  
  31. displaychat:
  32. Gui, Add, Edit, x6 y310 w350 h20 vsendtext,
  33. Gui, Add, Button, x366 y310 w100 h20 gsend +default, Send
  34. Gui, Add, Edit, x6 y10 w350 h290 +readonly vchat,
  35. Gui, Add, Edit, x366 y10 w100 h290 +readonly vuserlist, %userlist%
  36. Gui, Show, h342 w477, AHK Chat
  37. Return
  38.  
  39. send:
  40. gui submit, nohide
  41. SetTimer, updatechat, off
  42. URLDownloadToFile, http://jon2s.com/ahkchat/chat.php?event=sendtext&loggedusername=%username%&msg=%sendtext%, %A_Temp%\sendtxt.txt
  43. gosub, updatechat
  44. guicontrol,, sendtext,
  45. SetTimer, updatechat, on
  46. return
  47.  
  48. updatechat:
  49. URLDownloadToFile, http://jon2s.com/ahkchat/chat.php?event=chat&loggedusername=%username%, %A_Temp%\chat.txt
  50. FileReadLine, chatnew, %A_Temp%\chat.txt, 1
  51. if chatnew <> ''
  52. {
  53.   chat = %chatnew% %chat%
  54. }
  55. StringReplace, chat, chat, &(), `n, 1
  56. guiControl,, chat, %chat%
  57. chatnew =
  58. URLDownloadToFile, http://jon2s.com/ahkchat/chat.php?event=userlist, %A_Temp%\userlist.txt
  59. FileReadLine, userlist, %A_Temp%\userlist.txt, 1
  60. StringReplace, userlist, userlist, &(), `n, 1
  61. guicontrol,, userlist, %userlist%
  62. return
  63.  
  64. GuiClose:
  65. URLDownloadToFile, http://jon2s.com/ahkchat/chat.php?event=logout&loggedusername=%username%, %A_Temp%\logout.txt
  66. FileDelete, %A_Temp%\logout.txt
  67. FileDelete, %A_Temp%\userlist.txt
  68. FileDelete, %A_Temp%\chat.txt
  69. FileDelete, %A_Temp%\login.txt
  70. FileDelete, %A_Temp%\send.txt
  71. ExitApp





MySQL Table ahkchat

  1. CREATE TABLE `ahkchatchat` (
  2.   `msgid` int(11) NOT NULL AUTO_INCREMENT,
  3.   `username` varchar(50) NOT NULL DEFAULT '',
  4.   `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  5.   `msg` text NOT NULL,
  6.   PRIMARY KEY  (`msgid`)
  7. ) ENGINE=MyISAM AUTO_INCREMENT=72 DEFAULT CHARSET=latin1 AUTO_INCREMENT=72 ;

MySQL Table

  1. CREATE TABLE `ahkchatusers` (
  2.   `userid` int(11) NOT NULL AUTO_INCREMENT,
  3.   `username` varchar(50) NOT NULL DEFAULT '',
  4.   `loggedin` char(3) NOT NULL DEFAULT '',
  5.   `ip` varchar(50) NOT NULL DEFAULT '',
  6.   `lastmsg` int(11) NOT NULL DEFAULT '0',
  7.   PRIMARY KEY  (`userid`)
  8. ) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ;

PHP Script

  1. <?php
  2. /* Warning codes,  put to errorlog
  3. W001: Username already in use
  4.  
  5.  
  6. */
  7.  
  8.  
  9. $event = $_GET['event'];
  10. $msg = $_GET['msg'];
  11. $username = $_GET['loggedusername'];
  12. $loggedusername = $_GET['loggedusername'];
  13.  
  14. if ($db = mysql_connect('**server**', '**username**', '**password**')) {
  15.    mysql_select_db('**database**', $db);
  16.    //echo 'Connected to the database.';
  17. } else {
  18.    die('Could not connect: ' . mysql_error());
  19. }
  20.  
  21.  
  22. if ($event == 'chat') {
  23.   $sql_events = mysql_query("SELECT * FROM ahkchatusers where username='$loggedusername' and loggedin='yes'") or die ( mysql_error());
  24.   while ($row = mysql_fetch_array($sql_events)) {
  25.     $lastmsg = $row["lastmsg"];
  26.   }
  27.   $sql_events2 = mysql_query("SELECT * FROM ahkchatchat where msgid>$lastmsg order by msgid desc") or die ( mysql_error());
  28.   while ($row = mysql_fetch_array($sql_events2)) {
  29.     $username = $row["username"];
  30.     $date = $row["date"];
  31.     $msg = $row["msg"];
  32.     $msgid = $row["msgid"];
  33.    $hour = date("g:i a", strtotime($date));
  34.    if ($username <> "SERVER_MSG") {
  35.       echo '[' . $hour . ']?' . $username . ' ?' . $msg . '&()';
  36.    }
  37.    else {
  38.       echo '[' . $hour . '] ' . $msg . '&()';
  39.    }
  40.  
  41.   }
  42.   if ($msgid != '') {
  43.     $query = "UPDATE ahkchatusers SET lastmsg='$msgid' where username='$loggedusername' and loggedin='yes'";
  44.     mysql_query($query) or die("Could not connect: " . mysql_error());
  45.   }
  46. }
  47.  
  48. if ($event == 'login') {
  49.   $sql_events3 = mysql_query("SELECT * FROM ahkchatusers where username='$username' limit 1") or die ( mysql_error());
  50.   while ($row = mysql_fetch_array($sql_events3)) {
  51.     $loggedin = $row["loggedin"];
  52.   }
  53.   if ($loggedin == 'yes') {
  54.   echo "Warning: W001";
  55.   }
  56.   if ($loggedin == 'no') {
  57.   $ip = GetHostByName($REMOTE_ADDR);
  58.   $query2 = "UPDATE ahkchatusers SET loggedin='yes', ip='$ip' where username='$username'";
  59.   mysql_query($query2) or die("Could not connect: " . mysql_error());
  60.   echo "success";
  61.   }
  62.   if ($loggedin == '') {
  63.   $ip = GetHostByName($REMOTE_ADDR);
  64.   $query3 = "INSERT INTO ahkchatusers (username, loggedin, ip) VALUES ('$username', 'yes', '$ip')";
  65.   mysql_query($query3) or die('Error, insert query failed');
  66.   echo "success";
  67.   }
  68.   $result = mysql_query("SELECT * FROM ahkchatchat") or die ( mysql_error());
  69.   $num_rows = mysql_num_rows($result);
  70.   $query4 = "UPDATE ahkchatusers SET lastmsg='$num_rows'";
  71.   mysql_query($query4) or die("Could not connect: " . mysql_error());
  72. }
  73.  
  74. if ($event == 'logout') {
  75.   $query5 = "UPDATE ahkchatusers SET loggedin='no' where username='$username'";
  76.   mysql_query($query5) or die("Could not connect: " . mysql_error());
  77. }
  78.  
  79. if ($event == 'sendtext') {
  80.   $query6 = "INSERT INTO ahkchatchat (username, msg) VALUES ('$username', '$msg')";
  81.   mysql_query($query6) or die('Error, insert query failed');
  82. }
  83.  
  84. if ($event == 'userlist') {
  85.   $sql_events4 = mysql_query("SELECT * FROM ahkchatusers where loggedin='yes'") or die ( mysql_error());
  86.   while ($row = mysql_fetch_array($sql_events4)) {
  87.     $username = $row["username"];
  88.     echo $username;
  89.     echo ' &()';
  90.   }
  91. }
  92.  
  93. if ($event == 'ping') {
  94.   mysql_query("UPDATE ahkchatusers SET lastping=CURRENT_TIMESTAMP WHERE username='$username'") or die('Error, insert query failed');
  95. }
  96.  
  97. if ($event == 'whoisactive') {
  98.    $query_myping = mysql_query("SELECT * FROM ahkchatusers where username='$username' limit 1") or die ( mysql_error());
  99.    while ($row = mysql_fetch_array($query_myping)) {
  100.    $myping = $row["lastping"];
  101.    }
  102.    $query_username = mysql_query("SELECT * FROM ahkchatusers where loggedin='yes'") or die ( mysql_error());
  103.    while ($row = mysql_fetch_array($query_username)) {
  104.       $username = $row["username"];
  105.  
  106.       $query_userping = mysql_query("SELECT * FROM ahkchatusers where username='$username' limit 1") or die ( mysql_error());
  107.       while ($row = mysql_fetch_array($query_userping)) {
  108.          $theirping = $row["lastping"];
  109.       }
  110.  
  111.       $mytime= strtotime($myping);
  112.       $theirtime= strtotime($theirping);
  113.       $diff = $mytime-$theirtime;
  114.      
  115.       if ($diff >= 30) {
  116.          mysql_query("UPDATE ahkchatusers SET loggedin='no' where username='$username'") or die('Error, insert query failed');
  117.          mysql_query("INSERT INTO ahkchatchat (username, msg) VALUES ('SERVER_MSG', 'Quits: $username (Connection timed out)')") or die('Error, insert query failed');
  118.       }
  119.    }
  120. }
  121.  
  122.  
  123. //username ='$username'
  124. //$query5 = "UPDATE ahkchatusers SET loggedin='no' where username='$username'";
  125. //UPDATE ahkchatusers SET lastping = CURRENT_TIMESTAMP WHERE userid =2 LIMIT 1 ;
  126.  
  127.  
  128. //2006-11-12 20:21:11
  129.  
  130. ?>



ahkusers mysql table

  1. CREATE TABLE `ahkchatusers` (
  2.   `userid` int(11) NOT NULL AUTO_INCREMENT,
  3.   `username` varchar(50) NOT NULL DEFAULT '',
  4.   `loggedin` char(3) NOT NULL DEFAULT '',
  5.   `ip` varchar(50) NOT NULL DEFAULT '',
  6.   `lastping` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  7.   `lastmsg` int(11) NOT NULL DEFAULT '0',
  8.   PRIMARY KEY  (`userid`)
  9. ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;



chat.php

  1. <?php
  2. /* Warning codes,  put to errorlog
  3. W001: Username already in use
  4.  
  5.  
  6. */
  7.  
  8.  
  9. $event = $_GET['event'];
  10. $msg = $_GET['msg'];
  11. $username = $_GET['loggedusername'];
  12. $loggedusername = $_GET['loggedusername'];
  13.  
  14. if ($db = mysql_connect('**server**', '**username**', '**password**')) {
  15.    mysql_select_db('**database**', $db);
  16.    //echo 'Connected to the database.';
  17. } else {
  18.    die('Could not connect: ' . mysql_error());
  19. }
  20.  
  21.  
  22. if ($event == 'chat') {
  23.   $sql_events = mysql_query("SELECT * FROM ahkchatusers where username='$loggedusername' and loggedin='yes'") or die ( mysql_error());
  24.   while ($row = mysql_fetch_array($sql_events)) {
  25.     $lastmsg = $row["lastmsg"];
  26.   }
  27.   $sql_events2 = mysql_query("SELECT * FROM ahkchatchat where msgid>$lastmsg order by msgid desc") or die ( mysql_error());
  28.   while ($row = mysql_fetch_array($sql_events2)) {
  29.     $username = $row["username"];
  30.     $date = $row["date"];
  31.     $msg = $row["msg"];
  32.     $msgid = $row["msgid"];
  33.    $hour = date("g:i a", strtotime($date));
  34.    if ($username <> "SERVER_MSG") {
  35.       echo '[' . $hour . ']?' . $username . ' ?' . $msg . '&()';
  36.    }
  37.    else {
  38.       echo '[' . $hour . '] ' . $msg . '&()';
  39.    }
  40.  
  41.   }
  42.   if ($msgid != '') {
  43.     $query = "UPDATE ahkchatusers SET lastmsg='$msgid' where username='$loggedusername' and loggedin='yes'";
  44.     mysql_query($query) or die("Could not connect: " . mysql_error());
  45.   }
  46. }
  47.  
  48. if ($event == 'login') {
  49.   $sql_events3 = mysql_query("SELECT * FROM ahkchatusers where username='$username' limit 1") or die ( mysql_error());
  50.   while ($row = mysql_fetch_array($sql_events3)) {
  51.     $loggedin = $row["loggedin"];
  52.   }
  53.   if ($loggedin == 'yes') {
  54.   echo "Warning: W001";
  55.   }
  56.   if ($loggedin == 'no') {
  57.   $ip = GetHostByName($REMOTE_ADDR);
  58.   $query2 = "UPDATE ahkchatusers SET loggedin='yes', ip='$ip' where username='$username'";
  59.   mysql_query($query2) or die("Could not connect: " . mysql_error());
  60.   echo "success";
  61.   }
  62.   if ($loggedin == '') {
  63.   $ip = GetHostByName($REMOTE_ADDR);
  64.   $query3 = "INSERT INTO ahkchatusers (username, loggedin, ip) VALUES ('$username', 'yes', '$ip')";
  65.   mysql_query($query3) or die('Error, insert query failed');
  66.   echo "success";
  67.   }
  68.   $result = mysql_query("SELECT * FROM ahkchatchat") or die ( mysql_error());
  69.   $num_rows = mysql_num_rows($result);
  70.   $query4 = "UPDATE ahkchatusers SET lastmsg='$num_rows'";
  71.   mysql_query($query4) or die("Could not connect: " . mysql_error());
  72. }
  73.  
  74. if ($event == 'logout') {
  75.   $query5 = "UPDATE ahkchatusers SET loggedin='no' where username='$username'";
  76.   mysql_query($query5) or die("Could not connect: " . mysql_error());
  77. }
  78.  
  79. if ($event == 'sendtext') {
  80.   $query6 = "INSERT INTO ahkchatchat (username, msg) VALUES ('$username', '$msg')";
  81.   mysql_query($query6) or die('Error, insert query failed');
  82. }
  83.  
  84. if ($event == 'userlist') {
  85.   $sql_events4 = mysql_query("SELECT * FROM ahkchatusers where loggedin='yes'") or die ( mysql_error());
  86.   while ($row = mysql_fetch_array($sql_events4)) {
  87.     $username = $row["username"];
  88.     echo $username;
  89.     echo ' &()';
  90.   }
  91. }
  92.  
  93. if ($event == 'ping') {
  94.   mysql_query("UPDATE ahkchatusers SET lastping=CURRENT_TIMESTAMP WHERE username='$username'") or die('Error, insert query failed');
  95. }
  96.  
  97. if ($event == 'whoisactive') {
  98.    $query_myping = mysql_query("SELECT * FROM ahkchatusers where username='$username' limit 1") or die ( mysql_error());
  99.    while ($row = mysql_fetch_array($query_myping)) {
  100.    $myping = $row["lastping"];
  101.    }
  102.    $query_username = mysql_query("SELECT * FROM ahkchatusers where loggedin='yes'") or die ( mysql_error());
  103.    while ($row = mysql_fetch_array($query_username)) {
  104.       $username = $row["username"];
  105.  
  106.       $query_userping = mysql_query("SELECT * FROM ahkchatusers where username='$username' limit 1") or die ( mysql_error());
  107.       while ($row = mysql_fetch_array($query_userping)) {
  108.          $theirping = $row["lastping"];
  109.       }
  110.  
  111.       $mytime= strtotime($myping);
  112.       $theirtime= strtotime($theirping);
  113.       $diff = $mytime-$theirtime;
  114.      
  115.       if ($diff >= 30) {
  116.          mysql_query("UPDATE ahkchatusers SET loggedin='no' where username='$username'") or die('Error, insert query failed');
  117.          mysql_query("INSERT INTO ahkchatchat (username, msg) VALUES ('SERVER_MSG', 'Quits: $username (Connection timed out)')") or die('Error, insert query failed');
  118.       }
  119.    }
  120. }
  121.  
  122.  
  123. //username ='$username'
  124. //$query5 = "UPDATE ahkchatusers SET loggedin='no' where username='$username'";
  125. //UPDATE ahkchatusers SET lastping = CURRENT_TIMESTAMP WHERE userid =2 LIMIT 1 ;
  126.  
  127.  
  128. //2006-11-12 20:21:11
  129.  
  130. ?>
반응형

'AUTOHOTKEY > 스크립트' 카테고리의 다른 글

HTML 태그 적용 시키기.  (0) 2007.12.22
글자를 포함한 스크린 샷을 찍습니다.  (0) 2007.12.22
XML 관련 함수  (0) 2007.11.13
ado com  (0) 2007.11.10
AHK BBCodeWriter v7.0.2 - An offline BBCode Editor  (0) 2007.11.04
Comments