1 module libinformer;
2 
3 import std.socket;
4 import bmessage;
5 import std.json;
6 import std.string;
7 import std.stdio;
8 
9 public final class BesterInformerClient
10 {
11     /* The informer socket */
12     private Socket informerSocket;
13 
14     this(string socketPath)
15     {
16         try
17         {
18             informerSocket = new Socket(AddressFamily.UNIX, SocketType.STREAM);
19             informerSocket.connect(new UnixAddress(socketPath));
20         }
21         catch(AddressException e)
22         {
23 
24         }
25         catch(SocketException e)
26         {
27 
28         }
29     }
30 
31     public string getServerInfo()
32     {
33         /* TODO: Implement me */
34         return "";
35     }
36 
37     public bool isClient(string username)
38     {
39         /* TODO: Implement me */
40         return true;
41     }
42 
43     public string[] getClients()
44     {
45         string[] clientList;
46 
47         JSONValue message;
48 
49         JSONValue commandBlock;
50         commandBlock["type"] = "listClients";
51 
52         message["command"] = commandBlock;
53 
54         sendMessage(informerSocket, message);
55 
56         JSONValue response;
57         receiveMessage(informerSocket, response);
58         
59         string statusCode = response["status"].str();
60 
61         if(cmp(statusCode, "0") == 0)
62         {
63             JSONValue[] clientListJSON = response["data"].array();
64             for(ulong i = 0; i < clientListJSON.length; i++)
65             {
66                 clientList ~= clientListJSON[i].str();
67             }
68         }
69         else
70         {
71             /* error */
72         }
73 
74         return clientList;
75     }
76 }