sources/main.cpp

changeset 10
3874575d924d
parent 8
8b697d30c49f
child 14
33b8f428bacb
--- a/sources/main.cpp	Thu Dec 11 16:17:35 2014 +0200
+++ b/sources/main.cpp	Fri Dec 12 00:55:51 2014 +0200
@@ -28,40 +28,71 @@
 	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#include <time.h>
+#include <sys/select.h>
 #include "main.h"
-#include "network/udpsocket.h"
+#include "network/rconsession.h"
 #include "huffman/huffman.h"
 
 // -------------------------------------------------------------------------------------------------
 //
+FUNCTION handle_input() -> void
+{
+	int ch = getch();
+}
+
+// -------------------------------------------------------------------------------------------------
+//
 FUNCTION
 main (int argc, char* argv[]) -> int
 {
 	HUFFMAN_Construct();
-	Bytestream packet;
-	packet.write_byte (0x34); // header
-	packet.write_byte (0x03); // version
-	UDPSocket socket;
-	assert (socket.set_blocking (false));
-	socket.send (IPAddress (localhost, 10666), packet);
-	Datagram datagram;
-
-	while (socket.read (datagram) == false)
-		;
+	/*
+	::initscr();
+	::start_color();
+	::raw();
+	::keypad (stdscr, true);
+	::noecho();
+	::refresh();
+	::timeout (0);
+	*/
+	Vector<RCONSession*> rconsessions;
+	RCONSession* sess = new RCONSession;
+	sess->set_password ("testpassword");
+	sess->connect (IPAddress (localhost, 10666));
+	rconsessions << sess;
 
-	printf ("Recieved datagram of %lu bytes from %s\n", datagram.data.written_length(), datagram.from.to_string (IP_WITH_PORT).chars());
-	HUFFMAN_Destruct();
-	return 0;
+	for (;;)
+	{
+		fd_set fdset;
+		int highest = 0;
+		timeval timeout;
+		timeout.tv_sec = 0;
+		timeout.tv_usec = 250000; // 0.25 seconds
+		FD_ZERO (&fdset);
+		//FD_SET (0, &fdset);
 
-	initscr();
-	start_color();
-	raw();
-	keypad (stdscr, true);
-	noecho();
-	refresh();
-	printw ("Hello, world from %s %s (%s)",
-		APPNAME, full_version_string(), changeset_date_string());
-	getch();
+		for (RCONSession* session : rconsessions)
+		{
+			int fd = session->socket()->file_descriptor();
+			highest = max (highest, fd);
+			FD_SET (fd, &fdset);
+		}
+
+		select (highest + 1, &fdset, nullptr, nullptr, &timeout);
+
+		/*
+		if (FD_ISSET (0, &fdset))
+		{
+			// stdin is ready, what's incoming?
+			handle_input();
+		}
+		*/
+
+		for (RCONSession* session : rconsessions)
+			session->tick();
+	}
+
 	endwin();
 	return EXIT_SUCCESS;
 }

mercurial