My favorites
▼
|
Sign in
cubbers-eqemu-utils
Cubber's custom tools for the EverQuest Emulator Server Project
Project Home
Downloads
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
EQEmuJSM
/
src
/
eqemujsm
/
telnet
/
eqemuTelnet.java
r9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
File: eqemuTelnet.java
Copyright (C) 2010: Ronny L. Bull (aka: Cubber)
Date: 9-03-2010
Development OS: Gentoo Linux
Java Version: sun-jdk-1.6.0.20
Description: EQEmu Java Server Manager - Telnet Functions
License:
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
Code Adaption Notice:
This code was adapted from the sample found here:
http://www.informit.com/guides/content.aspx?g=java&seqNum=40
*/
/*
Dependency Notice:
This code requires the apache commons package that can be found here:
http://commons.apache.org/net/
*/
package eqemujsm.telnet;
//Imports
import org.apache.commons.net.telnet.*;
import java.io.*;
public class eqemuTelnet
{
//Variables
private TelnetClient telnet = new TelnetClient();
private InputStream in;
private PrintStream out;
private char prompt = '>';
public eqemuTelnet( String server, int port, String user, String password )
{
try
{
//Connect to the server
telnet.connect(server, port);
//Get input and output stream references
in = telnet.getInputStream();
out = new PrintStream( telnet.getOutputStream() );
//Log in user
readUntil( "Username: ");
write( user );
readUntil( "Password: ");
write( password );
//Advance to prompt
readUntil( prompt + " " );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
public String readUntil( String pattern )
{
try
{
char lastChar = pattern.charAt( pattern.length() - 1 );
StringBuffer sb = new StringBuffer();
char ch = ( char )in.read();
while( true )
{
System.out.print( ch );
sb.append( ch );
if( ch == lastChar )
{
if( sb.toString().endsWith( pattern ) )
{
return sb.toString();
}
}
ch = ( char )in.read();
}
}
catch ( Exception e )
{
e.printStackTrace();
}
return null;
}
public void write( String value )
{
try
{
out.println( value );
out.flush();
System.out.println( value );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
public String sendCommand( String command )
{
try
{
write( command );
return readUntil( prompt + " " );
}
catch( Exception e )
{
e.printStackTrace();
}
return null;
}
public void disconnect()
{
try
{
telnet.disconnect();
}
catch( Exception e )
{
e.printStackTrace();
}
}
}
Show details
Hide details
Change log
r8
by RonnyBull on Oct 2, 2010
Diff
added EQEmuJSM source
Go to:
/trunk/EQEmuJSM
/trunk/EQEmuJSM/.classpath
/trunk/EQEmuJSM/.project
/trunk/EQEmuJSM/License
/trunk/EQEmuJSM/License/gpl-2.0.txt
/trunk/EQEmuJSM/PreCompiled
...led/EQEmuJSM_Rev_Alpha_0.0.2.jar
/trunk/EQEmuJSM/bin
/trunk/EQEmuJSM/bin/eqemujsm
...nk/EQEmuJSM/bin/eqemujsm/console
...n/eqemujsm/console/Console.class
/trunk/EQEmuJSM/bin/eqemujsm/gui
.../bin/eqemujsm/gui/eqemuJSM.class
/trunk/EQEmuJSM/bin/eqemujsm/telnet
...qemujsm/telnet/eqemuTelnet.class
/trunk/EQEmuJSM/commons-net-2.0
...uJSM/commons-net-2.0/LICENSE.txt
...muJSM/commons-net-2.0/NOTICE.txt
.../EQEmuJSM/commons-net-2.0/README
...EQEmuJSM/commons-net-2.0/apidocs
....0/apidocs/allclasses-frame.html
.../apidocs/allclasses-noframe.html
...2.0/apidocs/constant-values.html
...2.0/apidocs/deprecated-list.html
...commons-net-2.0/apidocs/examples
...apidocs/examples/FTPExample.html
...pidocs/examples/FTPSExample.html
...2.0/apidocs/examples/IOUtil.html
...examples/SubnetUtilsExample.html
...xamples/TelnetClientExample.html
....0/apidocs/examples/chargen.html
...t-2.0/apidocs/examples/class-use
...amples/class-use/FTPExample.html
...mples/class-use/FTPSExample.html
...s/examples/class-use/IOUtil.html
...lass-use/SubnetUtilsExample.html
...ass-use/TelnetClientExample.html
.../examples/class-use/chargen.html
.../examples/class-use/daytime.html
...ocs/examples/class-use/echo.html
...s/examples/class-use/finger.html
...s/examples/class-use/fwhois.html
...ocs/examples/class-use/mail.html
...examples/class-use/messages.html
...cs/examples/class-use/rdate.html
...cs/examples/class-use/rexec.html
...s/examples/class-use/rlogin.html
...s/examples/class-use/rshell.html
.../class-use/server2serverFTP.html
...ocs/examples/class-use/tftp.html
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 3152 bytes, 153 lines
View raw file
Powered by
Google Project Hosting