emoyasha Posted January 20, 2008 Share Posted January 20, 2008 (edited) hello i have made a lot of upgrades and tweaks to ocobra messenger, however there s a problem, it displays all offline users as EmoYasha (the admin account) not the actual usernames. please help me fix expandcollapse popup; ---------------------------------------------------------------- ; -> All the code in this server is up to date. <- ; -> It is equally functional as the release version. <- ; -> <- ; -> Created by: Manadar <- ; ---------------------------------------------------------------- ; Includes ; -------- ;#NoTrayIcon #include <GUIConstants.au3> #include <Array.au3> #include <String.au3>; Stringencrypt only. ; Server doesn't pause when tray is clicked. Pausing the server = bad idea. Opt("TrayAutoPause", 0) Opt("TrayOnEventMode", 1) ; Log in/out register requests ; ---------------------------- Global Const $AUTHORIZE = "AUT" Global Const $LOGOUT = "OUT" Global Const $REGISTER = "REG" Global Const $ACTIVATE = "ACT" ; Update request Global Const $DOWNLOAD = "DNL" ; Common requests ; --------------- Global Const $GETSTATE = "GST" Global Const $MESSAGE = "MSG" Global Const $CHANGENAME = "CHG" ; Contacts requests ; ----------------- Global Const $ADDUSER = "ADD" Global Const $DELUSER = "DEL" Global Const $GETLIST = "GET" ; Responses ; --------- Global Const $ACKNOWLEDGE = "ACK" Global Const $DENIAL = "DIE" Global Const $ERROR = "ERR" ; Options Dim $MaxConnections = 5 ; Variable declaration Dim $AppTitle = "Cobra Server" Dim $Ini = "Database.ini" Dim $GUI, $Edit Dim $CurrentClientVersion = IniRead($Ini,"GeneralConfig", "CurrentClientVersion", "v0.3.9") Dim $NewClientLocation = IniRead($Ini,"GeneralConfig", "NewClientLocation", "http://rsihq.us/update.exe") Dim $Socket[$MaxConnections] Dim $Index[$MaxConnections] Dim $Email[1] Dim $Password[1] Dim $DispName[1] Dim $NewSocket Dim $MainSocket ; Get users list ; -------------- If Not FileExists($Ini) Then ; First time the server initializes, ask the user to set a password. GUICreate($AppTitle, 248, 176, 193, 115) GUISetFont(10, 400, 0, "Verdana") GUICtrlCreateLabel("The server requires a administrator account to be set. Do this now or press Cancel to stop booting the server.", 5, 5, 236, 75) GUICtrlCreateLabel("Password", 5, 120, 66, 25) GUICtrlCreateLabel("Email", 5, 90, 68, 25) $User = GUICtrlCreateInput("Admin", 75, 90, 170, 24) $Pass = GUICtrlCreateInput("", 75, 120, 170, 24, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL)) $Create = GUICtrlCreateButton("Create", 90, 150, 75, 21, 0) $Cancel = GUICtrlCreateButton("Cancel", 170, 150, 75, 21, 0) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $Cancel Exit Case $Create ExitLoop EndSwitch WEnd $Email[0] = GUICtrlRead($User) $Password[0] = _StringEncrypt(1,GUICtrlRead($Pass),$Email[0]) $DispName[0] = "Administrator" IniWrite($Ini,"GeneralConfig","AdminAccount",$Email[0]) IniWrite($Ini,$Email[0],"Password", $Password[0]) IniWrite($Ini,$Email[0],"DisplayName", "Administrator") IniWrite($Ini,$Email[0],"Activated", 1) GUIDelete() EndIf Opt("GUIOnEventMode", 1) TrayCreateItem("Debug User Information") TrayItemSetOnEvent(-1,"Debug") TrayCreateItem("") TrayCreateItem("Disconnect All") TrayItemSetOnEvent(-1,"DisconnectAll") TrayCreateItem("Display Users") TrayItemSetOnEvent(-1,"Info") TrayCreateItem("") TrayCreateItem("Global Message") TrayItemSetOnEvent(-1,"GlobalMessage") ;Users array structure documentation ;-------------------------- #cs $Email[n] = Email of each user $Password[n] = Password of each user $Contacts[n][Int] = Array of contacts of a user, example: $Contacts[0][0] = 2 $Contacts[0][1] = Manadar $Contacts[0][2] = Admin $Contacts[1][0] = 1 $Contacts[1][1] = Kim #ce ; Create user array structure ; --------------------------- Global $Email = IniReadSectionNames($Ini) _ArrayDelete($Email,0) _ArrayDelete($Email,0) For $x = 0 to UBound($Email)-1 If IniRead($Ini,$Email[$x],"Activated", 0) = 1 Then _ArrayAdd($Password, IniRead($Ini,$Email[$x],"Password", "??NoPassword??")) _ArrayAdd($DispName, IniRead($Ini,$Email[$x],"DisplayName", "??NoDisplayname??")) Else _ArrayDelete($Email,$x) EndIf Next _ArrayDelete($Password,0) _ArrayDelete($DispName,0) ; Initialize TCP ; -------------- TCPStartup() $MainSocket = TCPListen(@IPAddress1,48130) If @error Then MsgBox(0, $AppTitle, "Fatal Error. Server unable to initliaze. Error no. " & @error) Exit EndIf TrayTip("Notification", $AppTitle & " running.", 2,1) ConsoleWrite($AppTitle & " running."&@CRLF) ; Main loop ; --------- While 1 ; Check for new connections ; ------------------------- $NewSocket = TCPAccept($MainSocket) If Not @error AND $NewSocket <> -1 Then $n = FindEmptySocket() If Not @error Then $Socket[$n] = $NewSocket $Index[$n] = -1 Else TCPCloseSocket($NewSocket) EndIf EndIf ; Check all existing connections ; ------------------------------ For $n = 0 to $MaxConnections-1 If $Socket[$n] <> "" Then $Data = TCPRecv($Socket[$n],1024) If @error Then ; User disconnected ; ----------------- $Socket[$n] = "" $Index[$n] = -1 Else If $Data <> "" Then ; Command received ; ---------------- If $Data Then $Command = StringLeft($Data,3) If $Index[$n] = -1 Then ; User not logged in, check for Log in/out register commands. ; ----------------------------------------------------------- Switch $Command Case $AUTHORIZE ; Parse the log in command ; ------------------------ $Split = StringSplit($Data," ") If $Split[0] = 4 Then ; Check wether the client is the right version. If $Split[4] <> $CurrentClientVersion Then TCPSend($Socket[$n],$DOWNLOAD & " " & $NewClientLocation & " " & $CurrentClientVersion) Else ; The user has the right version. This is the actual logging in procedure. ; Check if user is already logged in ; Loop through the users for a valid Email | password For $i = 0 to UBound($Email)-1 If $Split[2] = $Email[$i] AND $Split[3] == $Password[$i] Then ; The right password has been found. ;check if the user is already logged in. For $j = 0 to UBound($Index)-1 If $Index[$j] > -1 Then If $Email[$Index[$j]] = $Split[2] Then TCPSend($Socket[$j],"OUT") ExitLoop EndIf EndIf Next $Index[$n] = $i TCPSend($Socket[$n],$ACKNOWLEDGE) ExitLoop ElseIf $i = UBound($Email)-1 Then ; End of loop reached, check wether the user requires activation If IniRead($Ini,$Split[2],"ActivationCode","") <> "" Then ; the user does need to activate his account TCPSend($Socket[$n],$ACTIVATE) Else ; the user has entered the wrong credentials or hasn't registered at all TCPSend($Socket[$n],$DENIAL) EndIf EndIf Next EndIf Else TCPSend($Socket[$n],$ERROR) EndIf Case $REGISTER $Split = StringSplit($Data," ") If $Split[0] == 4 Then ;$Split[2] = email ;$Split[3] = password encrypted ;$Split[4] = version If $Split[4] <> $CurrentClientVersion Then ; Send a message that the user should download the new version. TCPSend($Socket[$n],"DNL " & $NewClientLocation & " " & $CurrentClientVersion) Else ; Client is up to date. For $i = 0 to UBound($Email)-1 If $Split[2] = $Email[$i] Then TCPSend($Socket[$n], $DENIAL) ExitLoop ElseIf $i = UBound($Email)-1 Then $CurrentActivationCode = "" For $j = 0 to 20 If Random(0,1,1) Then $CurrentActivationCode &= Chr(Random(48,57,1)) Else $CurrentActivationCode &= Chr(Random(65,90,1)) EndIf Next IniWrite($Ini,$Split[2],"ActivationCode", $CurrentActivationCode) IniWrite($Ini,$Split[2],"Password", $Split[3]) IniWrite($Ini,$Split[2],"DisplayName", $Split[2]) SendActivationEmail($Split[2],$CurrentActivationCode) TCPSend($Socket[$n],$ACKNOWLEDGE) EndIf Next EndIf Else TCPSend($Socket[$n],$ERROR) EndIf Case $ACTIVATE $Split = StringSplit($Data," ") If $Split[0] == 3 Then ; $Split[2] = email ; $Split[3] = activation code $Read = IniRead($Ini,$Split[2],"ActivationCode", "") If $Read AND $Read = $Split[3] Then; Double check the user is not sending a empty string. IniWrite($Ini,$Split[2],"Activated",1) _ArrayAdd($Email,$Split[2]) _ArrayAdd($Password,IniRead($Ini,$Split[2],"Password","??NoPassword??")) _ArrayAdd($DispName,$Split[2]) IniDelete($Ini,$Split[2], "ActivationCode") TCPSend($Socket[$n],"ACK") Else TCPSend($Socket[$n],"DIE") EndIf Else TCPSend($Socket[$n],"ERR") EndIf Case Else TCPSend($Socket[$n],$ERROR) EndSwitch Else ; User logged in, check for common and user commands. ; --------------------------------------------------- Switch $Command Case $LOGOUT ; Clear the email from the logged in users. $Index[$n] = -1 TCPSend($Socket[$n],$ACKNOWLEDGE) Case $MESSAGE ; Parse the message command. ;--------------------------- $Split = StringSplit($Data," ") For $i = 0 to $MaxConnections-1 If ($Index[$i] > -1) AND $Email[$Index[$i]] = $Split[2] Then ; User is logged in, send the message and a acknowledge to the sender. TCPSend($Socket[$i],StringReplace($Data,$Email[$Index[$i]],$Email[$Index[$n]],1)) TCPSend($Socket[$n],$ACKNOWLEDGE) ExitLoop ElseIf $i = $MaxConnections-1 Then ; User is not logged in. TCPSend($Socket[$n],$DENIAL) EndIf Next Case $GETSTATE ; Parse the command that gets the state and displayname of a user. ; ------------------------------------------------ $Split = StringSplit($Data," ") If $Split[0] = 2 Then For $i = 0 to $MaxConnections-1 If ($Index[$i] > -1) Then If $Email[$Index[$i]] = $Split[2] Then ; User is online. TCPSend($Socket[$n], $ACKNOWLEDGE & " " & $DispName[$Index[$i]]) ExitLoop Else ; User is offline. TCPSend($Socket[$n], $DENIAL & " " & $DispName[$Index[$i]]) ExitLoop EndIf EndIf Next Else TCPSend($Socket[$n], $ERROR) EndIf ; User Commands ; ----------------------- Case $ADDUSER $Split = StringSplit($Data," ") If $Split[0] = 2 Then $Split = StringSplit($Data," ") $read = StringStripWS(IniRead($ini,$Email[$Index[$n]],"Contacts",""),7) If StringInStr($read,$Split[2]) Then TCPSend($Socket[$n],$DENIAL) Else For $i = 0 to UBound($Email)-1 If $Email[$i] = $Split[2] Then IniWrite($Ini,$Email[$Index[$n]],"Contacts", StringStripWS($read & " " & $Split[2],7)) TCPSend($Socket[$n],$ACKNOWLEDGE) ElseIf $i = UBound($Email)-1 Then ; User is not logged in. TCPSend($Socket[$n],$DENIAL) EndIf Next EndIf Else TCPSend($Socket[$n],$ERROR) EndIf Case $DELUSER $Split = StringSplit($Data," ") If $Split[0] = 2 Then $read = StringStripWS(IniRead($ini,$Email[$Index[$n]],"Contacts",""),7) $read = StringStripWS(StringReplace($read,$Split[2],""),7) IniWrite($Ini,$Email[$Index[$n]],"Contacts", $read) TCPSend($Socket[$n],$ACKNOWLEDGE) Else TCPSend($Socket[$n],$ERROR) EndIf Case $GETLIST $read = StringStripWS(IniRead($ini,$Email[$Index[$n]],"Contacts",""),7) TCPSend($Socket[$n],$GETLIST & " " & $read) Case $CHANGENAME $Split = StringSplit($Data," ") If $Split[0] = 2 Then $DispName[$Index[$n]] = $Split[2] TCPSend($Socket[$n],$ACKNOWLEDGE) Else TCPSend($Socket[$n],$ERROR) EndIf Case Else TCPSend($Socket[$n],$ERROR) EndSwitch EndIf EndIf EndIf EndIf EndIf Next Sleep(5) WEnd ; Functions ; --------- Func OnAutoItExit() TCPShutdown() EndFunc Func SendActivationEmail($e_Recipient, $e_Activation) FileWrite( $e_Recipient & ".txt" ,$e_Activation ) EndFunc;==>SendEmail Func SocketToIP($SHOCKET) Local $sockaddr = DLLStructCreate("short;ushort;uint;char[8]") Local $aRet = DLLCall("Ws2_32.dll","int","getpeername","int",$SHOCKET, "ptr",DLLStructGetPtr($sockaddr),"int_ptr",DLLStructGetSize($sockaddr)) If Not @error And $aRet[0] = 0 Then $aRet = DLLCall("Ws2_32.dll","str","inet_ntoa","int",DLLStructGetData($sockaddr,3)) If Not @error Then $aRet = $aRet[0] Else $aRet = 0 EndIf $sockaddr = 0 Return $aRet EndFunc Func FindEmptySocket() For $n = 0 to $MaxConnections-1 If $Socket[$n] = "" Then Return $n EndIf Next SetError(1) EndFunc ; Tray functions Func DisconnectAll() For $n = 0 to $MaxConnections-1 If $Socket[$n] <> "" Then TCPCloseSocket($Socket[$n]) $Socket[$n] = "" $Index[$n] = -1 EndIf Next EndFunc Func GlobalMessage() If $GUI = "" Then $GUI = GUICreate("Global Message", 471, 121, 193, 115) $Edit = GUICtrlCreateEdit("", 2, 2, 465, 89, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN)) GUICtrlCreateButton("Ok", 280, 95, 110, 22, 0) GUICtrlSetOnEvent(-1,"SendGlobal") GUICtrlCreateButton("Cancel", 395, 95, 75, 22, 0) GUICtrlSetOnEvent(-1,"CloseGlobal") EndIf GUISetState(@SW_SHOW) EndFunc Func CloseGlobal() If $GUI <> "" Then GUIDelete($GUI) $GUI = "" EndIf EndFunc Func SendGlobal() If $GUI <> "" Then $Text = GUICtrlRead($Edit) For $n = 0 to $MaxConnections-1 If $Socket[$n] <> "" AND ($Index > -1) Then TCPSend($Socket[$n],"MSG" & $Email[$Index[$n]] & " Server " & $Text) EndIf Next CloseGlobal() EndIf EndFunc Func Info() ; Display a tooltip with information about the current connections ; ---------------------------------------------------------------- Local $temp For $n = 0 to $MaxConnections-1 If ($Socket[$n] <> "" AND $Index[$n] > 1) OR ($Index[$n] > -1) Then $temp &= $Socket[$n] & ":" & @TAB & $Email[$Index[$n]] & @CRLF EndIf Next If $temp = "" Then $temp = "No clients online." EndIf TrayTip($AppTitle,$temp,10) EndFunc Func Debug() _ArrayDisplay($Email,"$Email - Debug") _ArrayDisplay($Password,"$Password - Debug") _ArrayDisplay($DispName,"$Dispname - Debug") EndFunc Edited March 21, 2018 by Melba23 User name removed by request Spoiler Admin Of:http://notmyspace.info [Under Development, looking for volunteers to help improve]http://PSNetCards.co.ukhttp://ZacnAndLindsey.com [Under development, not quite sure what to do with it yet]http://revelm.com------------------------------------Radio Streams:http://75.185.53.88:8000 [128kb/s 44kHz]http://75.185.53.88:8002 [22kb/s 22kHz](works on mobile phones)-----------------------------------My Server:Owned By: http://jumpline.comIP:66.84.19.220Bandwidth:200GBStorage Space:1TBNetwork Connection: 1GB/S[up and down]Operating System: Red Hat LinuxInstalled Apps:Webmail, phpBB, Majordomo, phpMyAdmin, MySQL, Active Server Pages, FrontPage Extensions 2002, GraphicsMagick, Mod Perl, Perl, PHP: Hypertext Preprocessor, Python(want cheap good webhosting, or need a place to park your domain? contact me)----------------------------------- Link to comment Share on other sites More sharing options...
emoyasha Posted January 20, 2008 Author Share Posted January 20, 2008 i tried severL SOULUTIONS none worked this is the code that diplays the users and their status ; Parse the command that gets the state and displayname of a user. ; ------------------------------------------------ $Split = StringSplit($Data," ") If $Split[0] = 2 Then For $i = 0 to $MaxConnections-1 If ($Index[$i] > -1) Then If $Email[$Index[$i]] = $Split[2] Then ; User is online. TCPSend($Socket[$n], $ACKNOWLEDGE & " " & $DispName[$Index[$i]]) ExitLoop Else ; User is offline. TCPSend($Socket[$n], $DENIAL & " " & $DispName[$Index[$i]]) ExitLoop EndIf EndIf Next Else TCPSend($Socket[$n], $ERROR) EndIf Spoiler Admin Of:http://notmyspace.info [Under Development, looking for volunteers to help improve]http://PSNetCards.co.ukhttp://ZacnAndLindsey.com [Under development, not quite sure what to do with it yet]http://revelm.com------------------------------------Radio Streams:http://75.185.53.88:8000 [128kb/s 44kHz]http://75.185.53.88:8002 [22kb/s 22kHz](works on mobile phones)-----------------------------------My Server:Owned By: http://jumpline.comIP:66.84.19.220Bandwidth:200GBStorage Space:1TBNetwork Connection: 1GB/S[up and down]Operating System: Red Hat LinuxInstalled Apps:Webmail, phpBB, Majordomo, phpMyAdmin, MySQL, Active Server Pages, FrontPage Extensions 2002, GraphicsMagick, Mod Perl, Perl, PHP: Hypertext Preprocessor, Python(want cheap good webhosting, or need a place to park your domain? contact me)----------------------------------- Link to comment Share on other sites More sharing options...
Swift Posted January 21, 2008 Share Posted January 21, 2008 This should be put in GUI Help..but...im not sure why...never tested/used this script...i will test it...and see what you mean... Link to comment Share on other sites More sharing options...
Swift Posted January 21, 2008 Share Posted January 21, 2008 Edit: and what is this supposted to do??? i see a global message...but no box or anything??? Link to comment Share on other sites More sharing options...
emoyasha Posted January 21, 2008 Author Share Posted January 21, 2008 you use my cclient to connect to oit. the problem is basic, where it sends denial it means the user is offline, however all users that are offline show up ad the admin account. Spoiler Admin Of:http://notmyspace.info [Under Development, looking for volunteers to help improve]http://PSNetCards.co.ukhttp://ZacnAndLindsey.com [Under development, not quite sure what to do with it yet]http://revelm.com------------------------------------Radio Streams:http://75.185.53.88:8000 [128kb/s 44kHz]http://75.185.53.88:8002 [22kb/s 22kHz](works on mobile phones)-----------------------------------My Server:Owned By: http://jumpline.comIP:66.84.19.220Bandwidth:200GBStorage Space:1TBNetwork Connection: 1GB/S[up and down]Operating System: Red Hat LinuxInstalled Apps:Webmail, phpBB, Majordomo, phpMyAdmin, MySQL, Active Server Pages, FrontPage Extensions 2002, GraphicsMagick, Mod Perl, Perl, PHP: Hypertext Preprocessor, Python(want cheap good webhosting, or need a place to park your domain? contact me)----------------------------------- Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now