sources/main.cpp

changeset 10
3874575d924d
parent 8
8b697d30c49f
child 14
33b8f428bacb
equal deleted inserted replaced
9:e7a09ceb4505 10:3874575d924d
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include <time.h>
32 #include <sys/select.h>
31 #include "main.h" 33 #include "main.h"
32 #include "network/udpsocket.h" 34 #include "network/rconsession.h"
33 #include "huffman/huffman.h" 35 #include "huffman/huffman.h"
36
37 // -------------------------------------------------------------------------------------------------
38 //
39 FUNCTION handle_input() -> void
40 {
41 int ch = getch();
42 }
34 43
35 // ------------------------------------------------------------------------------------------------- 44 // -------------------------------------------------------------------------------------------------
36 // 45 //
37 FUNCTION 46 FUNCTION
38 main (int argc, char* argv[]) -> int 47 main (int argc, char* argv[]) -> int
39 { 48 {
40 HUFFMAN_Construct(); 49 HUFFMAN_Construct();
41 Bytestream packet; 50 /*
42 packet.write_byte (0x34); // header 51 ::initscr();
43 packet.write_byte (0x03); // version 52 ::start_color();
44 UDPSocket socket; 53 ::raw();
45 assert (socket.set_blocking (false)); 54 ::keypad (stdscr, true);
46 socket.send (IPAddress (localhost, 10666), packet); 55 ::noecho();
47 Datagram datagram; 56 ::refresh();
57 ::timeout (0);
58 */
59 Vector<RCONSession*> rconsessions;
60 RCONSession* sess = new RCONSession;
61 sess->set_password ("testpassword");
62 sess->connect (IPAddress (localhost, 10666));
63 rconsessions << sess;
48 64
49 while (socket.read (datagram) == false) 65 for (;;)
50 ; 66 {
67 fd_set fdset;
68 int highest = 0;
69 timeval timeout;
70 timeout.tv_sec = 0;
71 timeout.tv_usec = 250000; // 0.25 seconds
72 FD_ZERO (&fdset);
73 //FD_SET (0, &fdset);
51 74
52 printf ("Recieved datagram of %lu bytes from %s\n", datagram.data.written_length(), datagram.from.to_string (IP_WITH_PORT).chars()); 75 for (RCONSession* session : rconsessions)
53 HUFFMAN_Destruct(); 76 {
54 return 0; 77 int fd = session->socket()->file_descriptor();
78 highest = max (highest, fd);
79 FD_SET (fd, &fdset);
80 }
55 81
56 initscr(); 82 select (highest + 1, &fdset, nullptr, nullptr, &timeout);
57 start_color(); 83
58 raw(); 84 /*
59 keypad (stdscr, true); 85 if (FD_ISSET (0, &fdset))
60 noecho(); 86 {
61 refresh(); 87 // stdin is ready, what's incoming?
62 printw ("Hello, world from %s %s (%s)", 88 handle_input();
63 APPNAME, full_version_string(), changeset_date_string()); 89 }
64 getch(); 90 */
91
92 for (RCONSession* session : rconsessions)
93 session->tick();
94 }
95
65 endwin(); 96 endwin();
66 return EXIT_SUCCESS; 97 return EXIT_SUCCESS;
67 } 98 }

mercurial