From d9aacb37055de77c7a1d10cc9874caec4b59d1f7 Mon Sep 17 00:00:00 2001
From: Sergei Reznikov <diver@gelios.net>
Date: Fri, 23 Nov 2018 15:17:26 +0300
Subject: Add missing include


diff --git a/src/network/nSocket.cpp b/src/network/nSocket.cpp
index d80f908..cad1c6e 100644
--- a/src/network/nSocket.cpp
+++ b/src/network/nSocket.cpp
@@ -45,7 +45,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include <errno.h>
 #include <stdlib.h>
 #include <vector>
-
+#include <sys/select.h>
 #ifndef WIN32
 #include <arpa/inet.h> 
 #include <netinet/in_systm.h>
-- 
2.30.2


From ecca5b573275ae093f7ba7823d254b2dcc86d9e1 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 19 May 2020 21:03:46 +1000
Subject: Fix build


diff --git a/src/network/nSocket.cpp b/src/network/nSocket.cpp
index cad1c6e..72862c8 100644
--- a/src/network/nSocket.cpp
+++ b/src/network/nSocket.cpp
@@ -2155,7 +2155,7 @@ int nSocket::Write( const int8 * buf, int len, const nAddress & addr ) const
 //!
 // *******************************************************************************************
 
-int nSocket::Broadcast( const char * buf, int len, unsigned int port ) const
+int nSocket::Broadcast( const int8 * buf, int len, unsigned int port ) const
 {
     tASSERT( IsOpen() );
 
diff --git a/src/network/nSocket.h b/src/network/nSocket.h
index 5d3dbb4..0c6b3f5 100644
--- a/src/network/nSocket.h
+++ b/src/network/nSocket.h
@@ -52,7 +52,11 @@ struct sockaddr;
 #include <netinet/in.h>
 #endif
 
+#ifdef __HAIKU__
+#include <SupportDefs.h>
+#else
 typedef  char int8;
+#endif
 
 //! union of supported internet addresses
 union nAddressBase
@@ -152,7 +156,7 @@ class PermanentError: public tException
 
     int Read        ( int8 *buf, int len, nAddress & addr )             const; //!< reads data from the socket
     int Write       ( const int8 *buf, int len, const nAddress & addr ) const; //!< writes data to the socket
-    int Broadcast   ( const char *buf, int len, unsigned int port )     const; //!< broadcasts data over the socket to the LAN
+    int Broadcast   ( const int8 *buf, int len, unsigned int port )     const; //!< broadcasts data over the socket to the LAN
 
     nAddress const &   GetAddress( void )                  const   ;	//!< Gets the address the socket is bound to
     nSocket const &    GetAddress( nAddress & address )    const   ;	//!< Gets the address the socket is bound to
-- 
2.30.2


From 2505997d76d19e6a28f67a6f7c619b90d5f68e8f Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Wed, 20 May 2020 08:44:37 +1000
Subject: Fix argv[0] for launch from symlink


diff --git a/src/tron/gArmagetron.cpp b/src/tron/gArmagetron.cpp
index 34949f5..56c8f2a 100644
--- a/src/tron/gArmagetron.cpp
+++ b/src/tron/gArmagetron.cpp
@@ -607,7 +607,11 @@ tConfItem<tString> sn_configurationSavedInVersionConf("SAVED_IN_VERSION",sn_conf
 int main(int argc,char **argv){
     //std::cout << "enter\n";
     //  net_test();
-
+#ifdef __HAIKU__
+	char *binpath = realpath(argv[0], NULL);
+	if (binpath != NULL)
+		argv[0] = binpath;
+#endif
     bool dedicatedServer = false;
 
     //  std::cout << "Running " << argv[0] << "...\n";
-- 
2.30.2


From 240055e845167e96f23c2ebc6cded3700ce8cf9b Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 27 Sep 2021 11:09:57 +1000
Subject: SOCK_CLOEXEC and IPTOS_LOWDELAY not supported


diff --git a/src/network/nSocket.cpp b/src/network/nSocket.cpp
index 72862c8..46d3cd4 100644
--- a/src/network/nSocket.cpp
+++ b/src/network/nSocket.cpp
@@ -1518,7 +1518,7 @@ int nSocket::Create( void )
     sn_InitOSNetworking();
 
     int socktype = socktype_;
-#ifndef WIN32
+#if !defined(WIN32) && !defined(__HAIKU__)
     socktype |= SOCK_CLOEXEC;
 #endif
 
@@ -1529,7 +1529,7 @@ int nSocket::Create( void )
 
     // set TOS to low latency ( see manpages getsockopt(2), ip(7) and socket(7) )
     // maybe this works for Windows, too?
-#ifndef WIN32
+#if !defined(WIN32) && !defined(__HAIKU__)
     char tos = IPTOS_LOWDELAY;
 
     setsockopt( socket_, IPPROTO_IP, IP_TOS, &tos, sizeof(char) );
-- 
2.30.2


From d8dd93a242fbd76f2b08ce425ad68712c771b302 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Mon, 27 Sep 2021 12:13:07 +1000
Subject: Fix crash on exit


diff --git a/src/tron/gArmagetron.cpp b/src/tron/gArmagetron.cpp
index 56c8f2a..fb48580 100644
--- a/src/tron/gArmagetron.cpp
+++ b/src/tron/gArmagetron.cpp
@@ -788,7 +788,7 @@ int main(int argc,char **argv){
                 SDL_Init(SDL_INIT_VIDEO) < 0 )            {
                 tERR_ERROR("Couldn't initialize SDL: " << SDL_GetError());
             }
-            atexit(SDL_Quit);
+            //atexit(SDL_Quit);
 
             sr_glRendererInit();
 
@@ -864,10 +864,10 @@ int main(int argc,char **argv){
                 //std::cout << "saved\n";
 
                 //    cleanup(grid);
-                SDL_QuitSubSystem(SDL_INIT_VIDEO);
+                //SDL_QuitSubSystem(SDL_INIT_VIDEO);
             }
             se_SoundExit();
-            SDL_Quit();
+            SDL_QuitSubSystem(SDL_INIT_AUDIO);
 #else
             sr_glOut=0;
 
-- 
2.30.2

