summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/CDDBConnection.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/CDDBConnection.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/CDDBConnection.java')
-rw-r--r--NET/worlds/scape/CDDBConnection.java75
1 files changed, 75 insertions, 0 deletions
diff --git a/NET/worlds/scape/CDDBConnection.java b/NET/worlds/scape/CDDBConnection.java
new file mode 100644
index 0000000..c446d1d
--- /dev/null
+++ b/NET/worlds/scape/CDDBConnection.java
@@ -0,0 +1,75 @@
+package NET.worlds.scape;
+
+import NET.worlds.network.DNSLookup;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.net.Socket;
+
+class CDDBConnection {
+ private Socket sock;
+ private PrintStream sockOut;
+ private DataInputStream sockIn;
+ private boolean readOnly;
+ private boolean debug;
+
+ public CDDBConnection(CDDBHost host, boolean debug) throws IOException {
+ this.debug = debug;
+ if (debug) {
+ System.out.println("Contacting host " + host);
+ }
+
+ this.sock = new Socket(DNSLookup.lookup(host.getHost()), host.getPort());
+ CDDBLookup.markActivity();
+ this.sockOut = new PrintStream(this.sock.getOutputStream(), true);
+ this.sockIn = new DataInputStream(this.sock.getInputStream());
+ String msg = this.recv();
+ if (msg.startsWith("200 ")) {
+ this.readOnly = false;
+ } else {
+ if (!msg.startsWith("201 ")) {
+ throw new IOException("Can't connect to " + host + ": " + msg);
+ }
+
+ this.readOnly = true;
+ }
+ }
+
+ public String command(String command) throws IOException {
+ this.send(command);
+ return this.recv();
+ }
+
+ public String readBody() throws IOException {
+ String str = this.recv();
+ return str.equals(".") ? null : str;
+ }
+
+ public void close() {
+ try {
+ this.send("quit");
+ this.recv();
+ this.sock.close();
+ } catch (IOException var2) {
+ }
+ }
+
+ private void send(String msg) throws IOException {
+ if (this.debug) {
+ System.out.println("--> " + msg);
+ }
+
+ this.sockOut.println(msg);
+ CDDBLookup.markActivity();
+ }
+
+ private String recv() throws IOException {
+ String msg = this.sockIn.readLine();
+ CDDBLookup.markActivity();
+ if (this.debug) {
+ System.out.println("<-- " + msg);
+ }
+
+ return msg;
+ }
+}