diff --git a/dub.json b/dub.json index 41b244b..a2f1d3a 100644 --- a/dub.json +++ b/dub.json @@ -4,7 +4,7 @@ ], "copyright": "Copyright © 2020, Tristan B. Kildaire", "dependencies": { - "tristanable": "~>0.0.28" + "tristanable": "~>0.0.29" }, "description": "dnet client", "license": "GPLv3", diff --git a/dub.selections.json b/dub.selections.json index 3746c19..1c4a95d 100644 --- a/dub.selections.json +++ b/dub.selections.json @@ -2,6 +2,6 @@ "fileVersion": 1, "versions": { "bformat": "1.0.8", - "tristanable": "0.0.28" + "tristanable": "0.0.29" } } diff --git a/source/app.d b/source/app.d index 0bcba24..fdafeda 100644 --- a/source/app.d +++ b/source/app.d @@ -2,20 +2,66 @@ import std.stdio; import tristanable.manager; import std.socket; +import client; +import std.string : cmp, split, strip; +import std.conv : to; void main() { - writeln("Edit source/app.d to start your project."); - - /* COnnect to the server */ - Socket socket = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.TCP); - - socket.connect(parseAddress("0.0.0.0",7777)); - - /* Create a new tristanable manager */ - Manager manager = new Manager(socket); - - manager.sendMessage(1, [0,4,65,66,66,65,69,69]); - - writeln(manager.receiveMessage(1)); + commandLine(); +} + +void commandLine() +{ + /* Current conneciton */ + DClient client; + + /* The current command */ + string commandLine; + + while(true) + { + /* Read in a command line */ + write("> "); + commandLine = readln(); + + if(cmp(strip(commandLine), "") == 0) + { + continue; + } + + string[] elements = split(commandLine); + string command = elements[0]; + + /* If the command is `exit` */ + if(cmp(command, "exit") == 0) + { + break; + } + /* If the command is `connect` */ + else if(cmp(command, "connect") == 0) + { + string address = elements[1]; + string port = elements[2]; + Address addr = parseAddress(address, to!(ushort)(port)); + + writeln("Connecting to "~to!(string)(addr)~"..."); + client = new DClient(addr); + writeln("Connected!"); + } + /* If the command is `auth` */ + else if(cmp(command, "auth") == 0) + { + string username = elements[1]; + string password = elements[2]; + + client.auth(username, password); + } + } + + if(client) + { + + } + } diff --git a/source/client.d b/source/client.d new file mode 100644 index 0000000..690c300 --- /dev/null +++ b/source/client.d @@ -0,0 +1,48 @@ +import tristanable.manager : Manager; +import std.socket; +import std.stdio; +import std.conv : to; + +public class DClient +{ + /** + * tristanabale tag manager + */ + private Manager manager; + + this(Address address) + { + /* Initialize the socket */ + Socket socket = new Socket(AddressFamily.INET, SocketType.STREAM, ProtocolType.TCP); + socket.connect(address); + + /* Initialize the manager */ + manager = new Manager(socket); + + //init(); + } + + public void init() + { + manager.sendMessage(1, [0,4,65,66,66,65,69,69]); + writeln(manager.receiveMessage(1)); + } + + public void auth(string username, string password) + { + byte[] data = [0]; + data ~= cast(byte)username.length; + data ~= username; + data ~= password; + writeln(data); + manager.sendMessage(1, data); + byte[] resp = manager.receiveMessage(1); + writeln("auth resp: "~to!(string)(resp)); + } + + public void disconnect() + { + manager.stopManager(); + writeln("manager stopped"); + } +} \ No newline at end of file