Sign in to follow this  
Followers 0
CodeMaster Rapture

Creating a recv history (TCP)

3 posts in this topic

Hey all,

I'm writing a test-bed for some telnet automation and trying to create a recv'd history so I can do auto-login and/or send commands based off of what the server says. I know the problem resides in my recv function, but I'm at a loss to where I'm getting extra @CRLFs from. Here is my code:

Func Telnet_Recv($hSocket,$maxlen = 65536)
    Local $Data = TCPRecv($hSocket,$maxlen)
    If (StringLen($Data) == 0) Then
        Return False
    EndIf
    
    $Data = StringReplace($Data,@LF & @CR,@CRLF)    ;Deal with older linux telnet servers that only send \n\r and replace with \r\n

    _AddLog("Telnet_Recv: Received (" & StringLen($Data) & " characters)" & @CRLF & "{" & @CRLF & $Data & @CRLF & "}")

    $Data = StringSplit($Data,@CRLF)            ;Split up my data into an array...
    _ArrayDelete($Data,0)                       ;Element 0 is number of lines, so delete this element...
    _ArrayConcatenate($Telnet_Buffer,$Data)     ;Concatenate the new data into my buffer
    If (UBound($Telnet_Buffer) > 2000) Then     ;If my buffer has grown over its limit
        ReDim $Telnet_Buffer[2000]              ;redim it.
    EndIf
    
    ;Refresh my recv'd buffer editbox if new lines were recv'd
    If (GUICtrlRead($hGUI_LBL_Lines) <> ("Lines: " & (UBound($Telnet_Buffer)-1))) Then  ;Ugly logic, I know, temporary debug code...
        Local $newData = _ArrayToString($Telnet_Buffer,@CRLF,1)                         ;Turn my buffer array into one big string
        GUICtrlSetData($hGUI_EDT_Lines,$newData)                                        ;Copy it to my editbox for viewing
        GUICtrlSetData($hGUI_LBL_Lines,(UBound($Telnet_Buffer)-1))                      ;Update my label telling me the size of my buffer
    EndIf
    Return True
EndFunc

So what I'm getting in my log is:

Telnet_Startup: Succeeded!
Telnet_Connect: Connected to www.temporal-rifts.org(216.136.9.5):7887 successfully!
Telnet_Recv: Received (1460 characters)
{

+
.             !                                !
   !           |>>>                             |>>>        !
   |>>>     |>>>                                |>>>        |>>>
   |_   _   _  |_                                 |_   _   _  |_
   | |_| |_| |_| |                               | |_| |_| |_| |
    \___________/   __   __   __   __   __   __ \___________/
     |%,     ,%|__  |  |_|  |_|  |_|  |_|  |_|  |  __|%,     ,%|
     |-%   .-.-|  |/     [][][][][][][][][]   \|  |-.-.  %- |
     | %,  | | |       []    Welcome      []        | | | ,%  | 
     |   -%|_| |      []         to      []    | |_|%-   |
     |   ,- |    []                   []      | -,   |    
     | ,% %,   |    []      Temporal        []   |   ,% %, |
``   |-.-. %   |   []         Rifts        []   |   % .-.-|
     |%| | -%, |   []__________________________[]   | ,%- | |%|
     | |_|   ,%|   []                         []    |%,   |_| |
     |  ,%,%-|   [] Based on Rom 2.4      []    |-%,%,  |
     |,%-%  %-,|   []                         []    |,%,  -%, |
    %|  %-   |   [] Heavily Modified      []    |  -%, -%,|%
   %%%-%,-   |   []                       []    |    -,%-%%%
 %%%%%][][][][]\___[]                         []___/[][][][][%%%%%   
%lc%%][][][][][]-"^"-                         -"^"-[][][][][][%%%%%
-"^"-"^"-"^"-"^"-                                 -
}
Telnet_Recv: Received (240 characters)
{
"^"-"^"-"^"-"^"-
 
This is an RP encouraged mud. Please choose an appropriate name for 
your character. If you fail to do so, you will be asked to choose a 
more appropriate one upon creation. 

By what name do you wish to be known?

}

And what I'm getting in my editbox is:

###START###


+

.             !                                !

   !           |>>>                             |>>>        !

   |>>>     |>>>                                |>>>        |>>>

   |_   _   _  |_                                 |_   _   _  |_

   | |_| |_| |_| |                               | |_| |_| |_| |

    \___________/   __   __   __   __   __   __ \___________/

     |%,     ,%|__  |  |_|  |_|  |_|  |_|  |_|  |  __|%,     ,%|

     |-%   .-.-|  |/     [][][][][][][][][]   \|  |-.-.  %- |

     | %,  | | |       []    Welcome      []        | | | ,%  | 

     |   -%|_| |      []         to      []    | |_|%-   |

     |   ,- |    []                   []      | -,   |    

     | ,% %,   |    []      Temporal        []   |   ,% %, |

``   |-.-. %   |   []         Rifts        []   |   % .-.-|

     |%| | -%, |   []__________________________[]   | ,%- | |%|

     | |_|   ,%|   []                         []    |%,   |_| |

     |  ,%,%-|   [] Based on Rom 2.4      []    |-%,%,  |

     |,%-%  %-,|   []                         []    |,%,  -%, |

    %|  %-   |   [] Heavily Modified      []    |  -%, -%,|%

   %%%-%,-   |   []                       []    |    -,%-%%%

 %%%%%][][][][]\___[]                         []___/[][][][][%%%%%   

%lc%%][][][][][]-"^"-                         -"^"-[][][][][][%%%%%

-"^"-"^"-"^"-"^"-                                 -
"^"-"^"-"^"-"^"-

 

This is an RP encouraged mud. Please choose an appropriate name for 

your character. If you fail to do so, you will be asked to choose a 

more appropriate one upon creation. 



By what name do you wish to be known?


###END###

As you can see, my buffer is getting 2 sets of @CRLFs per line somehow. Any clues?

-CMR

Share this post


Link to post
Share on other sites



Bueller? Bueller?

Share this post


Link to post
Share on other sites

It's rude to bump within 24 hours of your previous post. Please wait the standard "polite" time. It is also roughly 1:30 AM here and I don't know about the other coders but I'm quite tired.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0