some modifications for WIN32 support :)
authorpk910 <philipp@zoelle1.de>
Sun, 2 Oct 2011 01:41:34 +0000 (03:41 +0200)
committerpk910 <philipp@zoelle1.de>
Sun, 2 Oct 2011 01:41:34 +0000 (03:41 +0200)
.gitignore
Makefile.am
configure.ac
src/ClientSocket.c
src/cmd_neonserv_netinfo.c
src/main.c
src/main.h

index 4e8b61dbba9062ce986935a82c6afd2e807c7742..66e11f2f5249501959d3f733c86093a5d9324dff 100644 (file)
@@ -1,2 +1,22 @@
 mysqlConfig.h
-src/version.c
\ No newline at end of file
+src/version.c
+src/.deps
+src/.dirstamp
+src/*.o
+autom4te.cache
+aclocal.m4
+config.h.in~
+config.h.in
+config.h
+config.status
+config.log
+configure
+depcomp
+install-sh
+Makefile.in
+Makefile
+missing
+stamp-h1
+neonserv
+neonserv.exe
+libmysql.dll
\ No newline at end of file
index 409b9be7503ce956ce476706ace2ab24f40db361..a7f3b07fa9e575267d46c6007e8923d8c5ac66ee 100644 (file)
@@ -98,4 +98,4 @@ neonserv_SOURCES = src/version.c \
       src/cmd_neonserv_voiceall.c \
       src/cmd_neonserv_wipeinfo.c
 
-neonserv_LDADD = $(MYSQL_LIBS)
\ No newline at end of file
+neonserv_LDADD = $(MYSQL_LIBS) $(WINSOCK_LIBS)
\ No newline at end of file
index 308d5f4284472e475e8ca63bec8dd089e5de5dcc..a464dace120aaf0900557383a4d2bd3364a2ce0f 100644 (file)
@@ -11,21 +11,27 @@ AC_PROG_AWK
 
 # Checks for libraries.
 # Get MySQL library and include locations
-AC_ARG_WITH([mysql-include-path],
-  [AS_HELP_STRING([--with-mysql-include-path],
+AC_ARG_WITH([mysql],
+  [AS_HELP_STRING([--with-mysql=DIR],
     [location of the MySQL headers, defaults to /usr/include/mysql])],
   [MYSQL_CFLAGS="-I$withval"],
   [MYSQL_CFLAGS='-I/usr/include/mysql'])
 AC_SUBST([MYSQL_CFLAGS])
 
-AC_ARG_WITH([mysql-lib-path],
-  [AS_HELP_STRING([--with-mysql-lib-path], [location of the MySQL libraries])],
+AC_ARG_WITH([mysql-lib],
+  [AS_HELP_STRING([--with-mysql-lib=DIR], [location of the MySQL libraries])],
   [MYSQL_LIBS="-L$withval -lmysqlclient"],
   [MYSQL_LIBS='-lmysqlclient'])
 AC_SUBST([MYSQL_LIBS])
 
+AC_ARG_WITH([winsock],
+  [AS_HELP_STRING([--with-winsock], [use winsock (WIN32 systems)])],
+  [WINSOCK_LIBS='-lws2_32'],
+  [WINSOCK_LIBS=''])
+AC_SUBST([WINSOCK_LIBS])
+
 # Checks for header files.
-AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h])
+AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h windows.h winsock2.h])
 
 # Checks for typedefs, structures, and compiler characteristics.
 
index 62e367d7b9ce9ca4d21458211348aed287b675e9..f4288f291ec6360aa1e0b532aad62746de386eab 100644 (file)
@@ -48,6 +48,59 @@ struct ClientSocket* create_socket(char *host, int port, char *pass, struct User
     return client;
 }
 
+#ifdef WIN32
+
+int connect_socket(struct ClientSocket *client) {
+    if((client->flags & SOCKET_FLAG_CONNECTED)) return 1;
+    struct hostent *host;
+    struct sockaddr_in addr;
+    int sock;
+    addr.sin_addr.s_addr = inet_addr(client->host);
+    if (addr.sin_addr.s_addr == INADDR_NONE) {
+        host = gethostbyname(client->host);
+        if(!host) {
+            return SOCKET_ERROR;
+        }
+        memcpy(&(addr.sin_addr), host->h_addr_list[0], 4);
+    }
+    sock = socket(PF_INET, SOCK_STREAM, 0);
+    if (sock == -1)
+    {
+        perror("socket() failed");
+        return 0;
+    }
+
+    addr.sin_port = htons(client->port);
+    addr.sin_family = AF_INET;
+
+    if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1)
+    {
+        perror("connect() failed");
+        return 0;
+    }
+
+    client->sock = sock;
+    client->flags |= SOCKET_FLAG_CONNECTED;
+    client->connection_time = time(0);
+
+    //send the IRC Headers
+    char sendBuf[512];
+    int len;
+
+    if(client->pass) {
+        len = sprintf(sendBuf, "PASS :%s\n", client->pass);
+        write_socket(client, sendBuf, len);
+    }
+    len = sprintf(sendBuf, "USER %s 0 0 :%s\n", client->user->ident, client->user->realname);
+    write_socket(client, sendBuf, len);
+    len = sprintf(sendBuf, "NICK %s\n", client->user->nick);
+    write_socket(client, sendBuf, len);
+
+    return 1;
+}
+
+#else
+
 int connect_socket(struct ClientSocket *client) {
     if((client->flags & SOCKET_FLAG_CONNECTED)) return 1;
     struct hostent *host;
@@ -58,7 +111,7 @@ int connect_socket(struct ClientSocket *client) {
         host = gethostbyname(client->host);
         if (!host)
         {
-            herror("gethostbyname() failed");
+            perror("gethostbyname() failed");
             return 0;
         }
         addr.sin_addr = *(struct in_addr*)host->h_addr;
@@ -99,6 +152,8 @@ int connect_socket(struct ClientSocket *client) {
     return 1;
 }
 
+#endif
+
 int close_socket(struct ClientSocket *client) {
     if(client == NULL) return 0;
     if((client->flags & SOCKET_FLAG_CONNECTED))
index c8fd1b643d87ecaa4fea62678e2e0ca9912c8765..e8260d53c23bb6e40348d3b8182aa26db937eefa 100644 (file)
@@ -52,22 +52,22 @@ CMD_BIND(neonserv_cmd_netinfo) {
     table_add(table, content);
     
     content[0] = get_language_string(user, "NS_NETINFO_CHANNEL");
-    sprintf(tmp, "%d    %.2f kB (%d * %lu B = %.2f kB)", channel_count, channel_memory / 1024, channel_count, sizeof(struct ChanNode), channel_memory / 1024);
+    sprintf(tmp, "%d    %.2f kB (%d * %u B = %.2f kB)", channel_count, channel_memory / 1024, channel_count, (unsigned int) sizeof(struct ChanNode), channel_memory / 1024);
     content[1] = tmp;
     table_add(table, content);
     
     content[0] = get_language_string(user, "NS_NETINFO_CHANNEL_BAN");
-    sprintf(tmp, "%d    %.2f kB (%d * %lu B = %.2f kB)", channel_ban_count, channel_ban_memory / 1024, channel_ban_count, sizeof(struct BanNode), channel_ban_memory / 1024);
+    sprintf(tmp, "%d    %.2f kB (%d * %u B = %.2f kB)", channel_ban_count, channel_ban_memory / 1024, channel_ban_count, (unsigned int) sizeof(struct BanNode), channel_ban_memory / 1024);
     content[1] = tmp;
     table_add(table, content);
     
     content[0] = get_language_string(user, "NS_NETINFO_USER");
-    sprintf(tmp, "%d    %.2f kB (%d * %lu B = %.2f kB)", user_count, user_memory / 1024, user_count, sizeof(struct UserNode), user_memory / 1024);
+    sprintf(tmp, "%d    %.2f kB (%d * %u B = %.2f kB)", user_count, user_memory / 1024, user_count, (unsigned int) sizeof(struct UserNode), user_memory / 1024);
     content[1] = tmp;
     table_add(table, content);
     
     content[0] = get_language_string(user, "NS_NETINFO_CHANUSER");
-    sprintf(tmp, "%d    %.2f kB (%d * %lu B = %.2f kB)", chanuser_count, chanuser_memory / 1024, chanuser_count, sizeof(struct ChanUser), chanuser_memory / 1024);
+    sprintf(tmp, "%d    %.2f kB (%d * %u B = %.2f kB)", chanuser_count, chanuser_memory / 1024, chanuser_count, (unsigned int) sizeof(struct ChanUser), chanuser_memory / 1024);
     content[1] = tmp;
     table_add(table, content);
     
index 2fcc3dbec18349f0feae58657adb0cb8422dc1d1..0aa1a1bb8b2bec5be0908f34ec345c7ccb5e78e4 100644 (file)
@@ -36,6 +36,18 @@ int main(void)
 {
     start_time = time(0);
     
+    #ifdef WIN32
+    int res;
+    WSADATA wsadata;
+    // Start Windows Sockets.
+    res = WSAStartup(MAKEWORD(2, 0), &wsadata);
+    if (res)
+    {
+        perror("Unable to start Windows Sockets");
+        return 0;
+    }
+    #endif
+    
     init_mysql();
     init_lang();
     init_parser();
index b1452e76338b6049c5eded500dcbfd4918fef003..6e73985aae0ea0a9771f8abb85d788b9f92262fe 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#ifdef WIN32
+#include <windows.h>
+#include <winsock2.h>
+#else
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#include <unistd.h>
 #include <netdb.h>
+#endif
+#include <unistd.h>
 #include <stdarg.h>
 #include <time.h>