sources/main.cpp

branch
protocol5
changeset 106
7b156b764d11
parent 93
1ea012a6e1ec
child 109
e4966d7e615d
equal deleted inserted replaced
104:a76af67a3a4b 106:7b156b764d11
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 "main.h"
32
33 #ifndef _WIN32 31 #ifndef _WIN32
34 # include <sys/select.h> 32 # include <sys/select.h>
35 #else 33 #else
36 # include <winsock2.h> 34 # include <winsock2.h>
37 #endif 35 #endif
38 36
39 #include <time.h> 37 #include "main.h"
40 #include "network/rconsession.h" 38 #include "network/rconsession.h"
41 #include "huffman.h" 39 #include "huffman.h"
42 #include "interface.h" 40 #include "interface.h"
43 41
44 // ------------------------------------------------------------------------------------------------- 42 // -------------------------------------------------------------------------------------------------
45 // 43 //
46 FUNCTION 44 int main (int argc, char* argv[])
47 main (int argc, char* argv[]) -> int
48 { 45 {
49 #ifdef _WIN32 46 #ifdef _WIN32
47 # ifdef HAVE_PDCURSES_WIN32A
48 // PDCurses-win32a uses a GUI window of its own so we need to destroy the console window.
50 FreeConsole(); 49 FreeConsole();
50 # endif
51 51
52 WSADATA wsaData; 52 WSADATA wsaData;
53 int result = WSAStartup (MAKEWORD (2, 2), &wsaData); 53 int result = WSAStartup (MAKEWORD (2, 2), &wsaData);
54 54
55 if (result != 0) 55 if (result != 0)
65 { 65 {
66 fprintf (stderr, "usage: %s\nusage: %s <address> <password>\n", argv[0], argv[0]); 66 fprintf (stderr, "usage: %s\nusage: %s <address> <password>\n", argv[0], argv[0]);
67 return EXIT_FAILURE; 67 return EXIT_FAILURE;
68 } 68 }
69 69
70 Interface iface; 70 zfc::Interface iface;
71 71
72 if (argc == 3) 72 if (argc == 3)
73 iface.connect (argv[1], argv[2]); 73 iface.connect (argv[1], argv[2]);
74 74
75 try 75 try
83 timeout.tv_usec = 250000; // 0.25 seconds 83 timeout.tv_usec = 250000; // 0.25 seconds
84 FD_ZERO (&fdset); 84 FD_ZERO (&fdset);
85 FD_SET (0, &fdset); 85 FD_SET (0, &fdset);
86 86
87 int fd = iface.get_session()->socket()->file_descriptor(); 87 int fd = iface.get_session()->socket()->file_descriptor();
88 highest = max (highest, fd); 88 highest = zfc::max (highest, fd);
89 FD_SET (fd, &fdset); 89 FD_SET (fd, &fdset);
90 90
91 select (highest + 1, &fdset, nullptr, nullptr, &timeout); 91 select (highest + 1, &fdset, nullptr, nullptr, &timeout);
92 92
93 if (FD_ISSET (0, &fdset)) 93 if (FD_ISSET (0, &fdset))
98 98
99 iface.get_session()->tick(); 99 iface.get_session()->tick();
100 iface.render(); 100 iface.render();
101 } 101 }
102 } 102 }
103 catch (const Exitception&) {} 103 catch (const zfc::Exitception&) {}
104 104
105 iface.get_session()->disconnect(); 105 iface.get_session()->disconnect();
106 return EXIT_SUCCESS; 106 return EXIT_SUCCESS;
107 } 107 }

mercurial