Commits

Palmer, 2E0EOL committed a56fe3a

Entire changeset 0.1.2 -> 0.1.3

Comments (0)

Files changed (214)

 at least every server release.
 
 
+0.1.3
+-----
+DDRP: Add blake_NormNick() (nickname normalisation)
+DDRP: Make NormNick() thread safe
+DDRP: Fix configure not complaining when PTH wasn't installed
+DDRP: network_StartListening() UNIX portabillity increased
+DDRP: Fix a warning in blake_socket.c
+DDRP: Don't link Blake socket code twice
+DDRP: NetBuffer C wrapper (blake_netbuffer) made available
+DDRP: Fixed various boolean misalignments with new blake_bool_t
+DDRP: Fix db2fix missing clean rule
+DDRP: Enhancements to make_countries
+DDRP: Add RTTB library and tools to the tree
+DDRP: Ignore make depend failures
+DDRP: Control DPCRTLMM debugging options from main configuration
+DDRP: Fix NetBuffer ignoring CreateSocket()'s parameter
+Haesu: Various watchproc enhancements and fix of a warning
+DDRP: Add new error blakeArchivedFileError
+DDRP: Add blake_HashTypeName()
+DDRP: Fix language free of NULL pointer
+DDRP: Improvements to server_message locatabillity
+DDRP: Added a new file: blake/res/coup.txt
+DDRP: Fixed bug which didn't size blakeMessage properly after new flags1
+DDRP: Added benchmarking loop to Blake and testbed code
+
 0.1.2
 -----
 DDRP: Change privellege neccersary for OCQuery "die"
 
 include MasterMake.gnu
 
+ifdef DEBUG
+DPCRTLMM_OPTIONS=--disable-threads --enable-debug --enable-log --maxport
+RTTB_OPTIONS=--enable-debug
+else
+DPCRTLMM_OPTIONS=--disable-threads --disable-debug --disable-log --maxport
+RTTB_OPTIONS=--disable-debug
+endif
+
 # Master build rule
 all : _daybodep depend basictools memory_debugger libs blake_lib overchat cgi _clients _supdae advtools _testbed
 	cd buildtimer ; $(TMAKE) -f $(THISFILE) stop
 	@echo "                                                "
 	@echo "------------------------------------------------"
 	@echo
-	cd ads && $(TMAKE) -f $(THISFILE) depend
-	cd blake && $(TMAKE) -f $(THISFILE) depend
-	cd buildnum && $(TMAKE) -f $(THISFILE) depend
-	cd buildtimer && $(TMAKE) -f $(THISFILE) depend
-	cd c2raw && $(TMAKE) -f $(THISFILE) depend
-	cd cgi-bin && $(TMAKE) -f $(THISFILE) depend
-	cd clients && $(TMAKE) -f $(THISFILE) depend
-	cd committee && $(TMAKE) -f $(THISFILE) depend
-	cd configure && $(TMAKE) -f $(THISFILE) depend
-	cd daybodep && $(TMAKE) -f Makefile_oc.gnu depend
-	cd daybocrypt && $(TMAKE) -f Makefile_oc.gnu depend
-	cd db2fix && $(TMAKE) -f $(THISFILE) depend
-	cd dlini && $(TMAKE) -f $(THISFILE) depend
-	cd dpcrtlmm && $(TMAKE) -f $(THISFILE) depend
-	cd mailall && $(TMAKE) -f $(THISFILE) depend
-	cd NetBuffer && $(TMAKE) -f $(THISFILE) depend
-	cd occdtk && $(TMAKE) -f $(THISFILE) depend
-	cd ocquery && $(TMAKE) depend
-	cd raw2c && $(TMAKE) -f $(THISFILE) depend
-	cd rmw32 && $(TMAKE) -f $(THISFILE) depend
-	cd src && $(TMAKE) -f $(THISFILE) depend
-	cd testbed && $(TMAKE) -f $(THISFILE) depend
-	cd tools && $(TMAKE) -f $(THISFILE) depend
-	cd watchproc && $(TMAKE) -f $(THISFILE) depend
+	-cd ads && $(TMAKE) -f $(THISFILE) depend
+	-cd blake && $(TMAKE) -f $(THISFILE) depend
+	-cd buildnum && $(TMAKE) -f $(THISFILE) depend
+	-cd buildtimer && $(TMAKE) -f $(THISFILE) depend
+	-cd c2raw && $(TMAKE) -f $(THISFILE) depend
+	-cd cgi-bin && $(TMAKE) -f $(THISFILE) depend
+	-cd clients && $(TMAKE) -f $(THISFILE) depend
+	-cd committee && $(TMAKE) -f $(THISFILE) depend
+	-cd configure && $(TMAKE) -f $(THISFILE) depend
+	-cd daybodep && $(TMAKE) -f Makefile_oc.gnu depend
+	-cd daybocrypt && $(TMAKE) -f Makefile_oc.gnu depend
+	-cd db2fix && $(TMAKE) -f $(THISFILE) depend
+	-cd dlini && $(TMAKE) -f $(THISFILE) depend
+	-cd dpcrtlmm && $(TMAKE) -f $(THISFILE) depend
+	-cd mailall && $(TMAKE) -f $(THISFILE) depend
+	-cd NetBuffer && $(TMAKE) -f $(THISFILE) depend
+	-cd occdtk && $(TMAKE) -f $(THISFILE) depend
+	-cd ocquery && $(TMAKE) depend
+	-cd raw2c && $(TMAKE) -f $(THISFILE) depend
+	-cd rmw32 && $(TMAKE) -f $(THISFILE) depend
+	-cd rttb && $(TMAKE) -f $(THISFILE) depend
+	-cd src && $(TMAKE) -f $(THISFILE) depend
+	-cd testbed && $(TMAKE) -f $(THISFILE) depend
+	-cd tools && $(TMAKE) -f $(THISFILE) depend
+	-cd watchproc && $(TMAKE) -f $(THISFILE) depend
 
 basictools:
 	@echo "------------------------------------------------"
 	cd blake \
 	&& $(TMAKE) -f $(THISFILE)
 
-libs : dlini_lib daybocrypt_lib
+libs : dlini_lib daybocrypt_lib rttb_lib
 
 dlini_lib:
 	cd dlini && $(TMAKE) -f $(THISFILE)
 
 mrproper : clean
 	-rm -rf .resp
-	cd configure ; $(TMAKE) -f $(THISFILE) clean
+	cd configure && $(TMAKE) -f $(THISFILE) clean
 
-clean : testbed_clean advtools_clean supdae_clean clients_clean cgi_clean overchat_clean blake_lib_clean dlini_lib_clean memory_debugger_clean daybocrypt_clean basictools_clean daybodep_clean
+clean : testbed_clean advtools_clean supdae_clean clients_clean cgi_clean overchat_clean blake_lib_clean rttb_lib_clean dlini_lib_clean memory_debugger_clean daybocrypt_clean basictools_clean daybodep_clean
 	-rm -f core overchatd.core
 
 overchat_clean:
 	cd dlini ; $(TMAKE) -f $(THISFILE) clean
 
 daybocrypt_clean:
-	cd daybocrypt ; $(TMAKE) -f Makefile_oc.gnu clean
+	cd daybocrypt && $(TMAKE) -f Makefile_oc.gnu clean
+
+rttb_clean:
+	cd rttb && $(TMAKE) -f $(THISFILE) clean
 
 basictools_clean:
 	cd buildnum ; $(TMAKE) -f $(THISFILE) clean
 	cd buildtimer ; $(TMAKE) -f $(THISFILE) clean
 	cd watchproc ; $(TMAKE) -f $(THISFILE) clean
 
-memory_debugger : dpcrtlmm/libdpcrtlmm.a
+memory_debugger : dpcrtlmm/libdpcrtlmm$(LIB)
 
-dpcrtlmm/libdpcrtlmm.a:
+rttb_lib : rttb/librttb$(LIB)
+
+dpcrtlmm/libdpcrtlmm$(LIB):
 	@echo "------------------------------------------------"
 	@echo "                                                "
 	@echo "  Stage 3                                       "
 	@echo
 	cd dpcrtlmm \
 	&& $(TMAKE) -f $(THISFILE) config \
-	&& ./config --disable-threads \
-                    --disable-debug \
-                    --disable-log \
-                    --maxport \
+	&& ./config $(DPCRTLMM_OPTIONS) \
 	&& $(TMAKE) -f $(THISFILE) example
 
+rttb/librttb$(LIB):
+	cd rttb \
+	&& $(TMAKE) -f $(THISFILE) rttb_config \
+	&& ./rttb_config $(RTTB_OPTIONS) \
+	&& $(TMAKE) -f $(THISFILE) normal
+
 memory_debugger_clean:
-	cd dpcrtlmm ; $(TMAKE) -f $(THISFILE) clean
+	cd dpcrtlmm && $(TMAKE) -f $(THISFILE) clean
+
+rttb_lib_clean:
+	cd rttb && $(TMAKE) -f $(THISFILE) clean
 
 cgi:
 	@echo "------------------------------------------------"
-" " 
+#  /*
+#  OverChat
+#  by David Duncan Ross Palmer <Overlord@DayboLogic.co.uk>
+#  Copyright 2002 Daybo Logic, all rights reserved.
+#
+#  This file was auto generated by OverChat's autoconfigurator.
+#  Although the contents of the file, because they are written by
+#  machine and not by human belong to nobody, the program which created
+#  the file (overchat/configure/configure) is owned by DDRP.
+#  */
+
+#
+# Autogenerated makeinclude, do not edit
+#
+
+STATIC=-static
+CC=gcc
+CPPC=g++
+#DEBUG=1
+OPTLEVEL=
+TMAKE=tmake
+ANSI=-A
+MASTER_CFLAGS=-D__WIN32__  -c
+MASTER_LFLAGS=
+H=.h
+LIB=.lib
+EXE=.exe
+C=.c
+CPP=.cpp
+O=.obj
+WITH_PTH=1
+TV_DIR=.
+THISFILE=Makefile.bor
+DIR=dir /b
+STRIP=tdstrp32

NetBuffer/NetBuffer.cpp

 enum blakeError TNetBuffer::CreateSocket(int* PSocket)
 {
   s = network_CreateSocket(UseIPv6, false, false);
+  if ( PSocket ) *PSocket = s;
   if ( s == -1 ) { // Blake could not create a socket
     s = 0;
     return blakeUnknownFailure;
   }
 }
 //---------------------------------------------------------------------------
-enum NetBufferError TNetBuffer::Push(enum NetBufferDirection Direction, const void* Data, const size_t DataSize)
+enum blakeNetBufferError TNetBuffer::Push(enum blakeNetBufferDirection Direction, const void* Data, const size_t DataSize)
 {
-  enum NetBufferError err = nbeNoError;
+  enum blakeNetBufferError err = bnbeNoError;
 
   assert(Data && DataSize);
   if ( DataSize > OVERCHAT_NET_PKTMAXSZ * OVERCHAT_NET_TXSZ )
-    return nbeExtremeSize;
+    return bnbeExtremeSize;
 
   switch ( Direction ) {
-    case nbdIncoming : {
+    case bnbdIncoming : {
       if ( DataSize > (OVERCHAT_NET_PKTMAXSZ * OVERCHAT_NET_RXSZ) - inBuffLevel ) {
-        err = nbeCannotAccommodate;
+        err = bnbeCannotAccommodate;
         break;
       }
       memcpy((char*)inBuff + inBuffLevel, Data, DataSize);
       assert(inBuffLevel <= (OVERCHAT_NET_PKTMAXSZ * OVERCHAT_NET_RXSZ));
       break;
     }
-    case nbdOutgoing : {
+    case bnbdOutgoing : {
       if ( DataSize > (OVERCHAT_NET_PKTMAXSZ * OVERCHAT_NET_TXSZ) - outBuffLevel ) {
-        err = nbeCannotAccommodate;
+        err = bnbeCannotAccommodate;
         break;
       }
       memcpy((char*)outBuff + outBuffLevel, Data, DataSize);
       break;
     }
     default : {
-      err = nbeBadDirection;
+      err = bnbeBadDirection;
     }
   }
 
   return err;
 }
 //---------------------------------------------------------------------------
-size_t TNetBuffer::Pop(enum NetBufferDirection Direction, void* Data, const size_t MaxDataSize, enum NetBufferError* PNetError)
+size_t TNetBuffer::Pop(enum blakeNetBufferDirection Direction, void* Data, const size_t MaxDataSize, enum blakeNetBufferError* PNetError)
 {
-  enum NetBufferError err = nbeNoError;
+  enum blakeNetBufferError err = bnbeNoError;
   size_t ret = 0;
 
   assert(Data && MaxDataSize);
   switch ( Direction ) {
-    case nbdIncoming : {
+    case bnbdIncoming : {
       unsigned int MoveAmount = BLAKE_MIN(MaxDataSize, inBuffLevel);
       if ( MoveAmount ) {
         memcpy(Data, inBuff, MoveAmount);
       ret = MoveAmount;
       break;
     }
-    case nbdOutgoing : {
+    case bnbdOutgoing : {
       unsigned int MoveAmount = BLAKE_MIN(MaxDataSize, outBuffLevel);
       if ( MoveAmount ) {
         memcpy(Data, outBuff, MoveAmount);
       break;
     }
     default : {
-      err = nbeBadDirection;
+      err = bnbeBadDirection;
     }
   }
 
 
   while ( Amount ) {
     if ( marker == 0 ) { /* Begin new packet - length reader */
-      int nread = Pop(nbdIncoming, buff, 2, NULL); /* Read max two bytes (length indicator) */
+      int nread = Pop(bnbdIncoming, buff, 2, NULL); /* Read max two bytes (length indicator) */
       if ( !nread ) return;
       Amount -= nread; /* Remove from master packet independent bytes arrived marker */
       switch ( nread ) {
     }
     else if ( marker == 1 ) { /* Previously read half the length! */
       /* OK we only want one byte!  I don't care how much is waiting */
-      int nread = Pop(nbdIncoming, buff + 1, 1, NULL);
+      int nread = Pop(bnbdIncoming, buff + 1, 1, NULL);
       if ( !nread ) return;
       if ( nread != 1 ) goto setandunlock;
       marker++;
       }
       /* Back to some real work */
       if ( maxRead ) {
-        int nread = Pop(nbdIncoming, buff + marker, maxRead, NULL);
+        int nread = Pop(bnbdIncoming, buff + marker, maxRead, NULL);
         if ( !nread ) return;
         marker += nread;
         Amount -= nread;

NetBuffer/NetBuffer.h

 # include <string>
 #endif
 
-enum NetBufferError {
-  nbeNoError,
-  nbeCannotAccommodate,
-  nbeExtremeSize,
-  nbeBadDirection,
-  nbeSocketRegistered
-};
-
-enum NetBufferDirection {
-  nbdIncoming,
-  nbdOutgoing
-};
+/*
+  See blake.h for enumeration types and non-C++ compatibillity
+  interface
+*/
 
 #ifdef __cplusplus
 class TNetBuffer {
     enum blakeError CreateSocket(int* PSocket); /* Call before Connect() */
     enum blakeError Connect(const OVERCHAT_IP* Address);
     void Close(); /* Shut down the connection, socket becomes invalid */
-    enum NetBufferError Push(enum NetBufferDirection Direction, const void* Data, const size_t DataSize);
-    size_t Pop(enum NetBufferDirection Direction, void* Data, const size_t MaxDataSize, enum NetBufferError* PNetError);
+    enum blakeNetBufferError Push(enum blakeNetBufferDirection Direction, const void* Data, const size_t DataSize);
+    size_t Pop(enum blakeNetBufferDirection Direction, void* Data, const size_t MaxDataSize, enum blakeNetBufferError* PNetError);
     void PacketCompiler(size_t Amount);
     inline int GetSocket() /* Return the socket number we're using */
       { return s; }
 compiling packets.  This does of course make it difficult for other
 languages, but those programmers of those languages will have to fend on
 their own based on this authoritative source.
+
+Since OverChat 0.1.3 it is now possible to use NetBuffer through Blake's
+netbuffer_ wrapper functions in a procedural style.  This was done to
+allow other languages to more easily connect to the service.
+
+NOTICE: NetBuffer in it's present form may be heading for depreciation.

blake/Makefile.gnu

 THREAD_PTHINCLUDE=
 endif
 
-IPATH=-I../src -I. -I../dpcrtlmm -I../dlini $(THREAD_PTHINCLUDE) -I../daybocrypt
+IPATH=-I../src -I. -I../NetBuffer -I../dpcrtlmm -I../dlini $(THREAD_PTHINCLUDE) -I../daybocrypt -I../rttb/lib
 CFLAGS=$(MASTER_CFLAGS) $(IPATH)
-LFLAGS=$(MASTER_LFLAGS) ../libblake$(LIB) ../dpcrtlmm/libdpcrtlmm$(LIB) ../dlini/libdlini$(LIB) $(THREAD_LIBRARY) ../daybocrypt/libdaybocrypt$(LIB)
+LFLAGS=$(MASTER_LFLAGS) ../libblake$(LIB) ../dpcrtlmm/libdpcrtlmm$(LIB) ../dlini/libdlini$(LIB) $(THREAD_LIBRARY) ../daybocrypt/libdaybocrypt$(LIB) ../rttb/lib/librttb$(LIB)
 COMPILE=$(CC) $(CFLAGS)
+CPPCOMPILE=$(CPPC) $(CFLAGS)
 
 OBJECTS=blake$(O) \
         blake_cb$(O) \
         blake_portmutant$(O) \
         blake_portthread$(O) \
         blake_protocol$(O) \
-        blake_socket$(O) \
         blake_ansi$(O) \
         blake_strfunc$(O) \
         blake_trace$(O) \
         blake_chksum$(O) \
         blake_here$(O) \
         blake_authorisedclients$(O) \
+        blake_bench$(O) \
         blakedb$(O) \
         criticalinteger$(O) \
-        recursivemutant$(O)
+        recursivemutant$(O) \
+        blake_netbuffer$(O) \
+        NetBuffer$(O)
 
 RESFILES=res/btfuck$(O) \
          res/murder_microsoft$(O) \
-         res/sbeast$(O)
+         res/sbeast$(O) \
+         res/coup$(O)
 
 
 all : blake_lib queuetest dllclient
 blake_res:
 	cd res ; $(TMAKE) -f $(THISFILE)
 
-queuetest : queuetest$(O) ../libblake$(LIB) ../dlini/libdlini$(LIB)
-	$(CC) -oqueuetest queuetest$(O) $(LFLAGS)
+queuetest : queuetest$(O) ../libblake$(LIB)
+	$(CPPC) -oqueuetest queuetest$(O) $(LFLAGS)
 
 dllclient : dllclient$(O) ../libblake$(LIB)
-	$(CC) -odllclient dllclient$(O) $(LFLAGS)
+	$(CPPC) -odllclient dllclient$(O) $(LFLAGS)
 
 ../libblake$(LIB) : $(OBJECTS) blake_res    # Unfortunately this means libblake.a is _always_ rebuilt
 	ar cru ../libblake$(LIB) $(OBJECTS) $(RESFILES)
 	ranlib ../libblake$(LIB)
 
 
+NetBuffer$(O) : ../NetBuffer/NetBuffer$(CPP)
+	$(CPPCOMPILE) $<
+
 # Automatic rule for all the rest of the C files in Blake
 $(C)$(O):
 	$(COMPILE) $<
 
+$(CPP)$(O):
+	$(CPPCOMPILE) $<
+
 clean:
 	-$(RM) $(OBJECTS)
 	echo " " > .depend
Empty file added.

blake/blake.DSW

Binary file added.

blake/blake.OBR

Binary file added.
   existing in a C++ module, OVERCHAT_C_IN_CPP must be placed _before_ the
   declaration.  In C++, void in a prototype is not expected, in C it is.
   Therefore if there are no paramters to a function, OVERCHAT_PROTOTYPE_VOID
-  must be placed in place of the parameter list.
+  must be placed in place of the parameter list.  For example:
+  OVERCHAT_C_IN_CPP void Function(OVERCHAT_PROTOTYPE_VOID);
 */
 #ifdef __cplusplus /* C++ */
 # define OVERCHAT_C_IN_CPP extern "C"
   blakeExclusiveFileFailure,  /* Can't open a file for exclusive access */
   blakeBadSAHandle,           /* The SafeAllocator handle is unrecognised */
   blakeDbRecordCorrupt,       /* Database record is corrupt (checksum) */
-  blakeFileTruncated          /* File is too short! */
+  blakeFileTruncated,         /* File is too short! */
+  blakeArchivedFileError      /* Error opening archived file */
+};
+
+/*
+  NetBuffer errors
+*/
+enum blakeNetBufferError {
+  bnbeNoError,
+  bnbeCannotAccommodate,
+  bnbeExtremeSize,
+  bnbeBadDirection,
+  bnbeSocketRegistered,
+  bnbeUninitialised, /* NetBuffer not set up! */
+  bnbeSocketNotRegistered, /* Only used by blake_netbuffer wrapper */
+  bnbeNotEnoughMem /* Allocation/construction failed */
+};
+
+/*
+  NetBuffer direction
+*/
+enum blakeNetBufferDirection {
+  bnbdIncoming,
+  bnbdOutgoing
 };
 
 /*
   bccreserved0,              /* This one's reserved for my later usage */
   bccnonsense0,              /* Completely bogus code */
   bccversion,                /* Request server version */
-  bccmessage,                /* Send an instant message (or offline message) to a user */
+  bccmessage,                /* Send an instant message, offline message or notice to a user */
   bccchatmsg,                /* Send a message to a chat room (must ibe in the chat and with voice privelledge) */
   bccwhois,                  /* Get details of any user */
   bccundocumented0,          /* A secret backdoor ;) */
 typedef unsigned char blake_byte_t;
 /* Declaration of fixed type blake_word8_t */
 typedef unsigned char blake_word8_t;
+/* Declaration of fixed type blake_byte_t */
+typedef unsigned char blake_bool_t;
 
 /* Declaration of fixed type blake_word16_t */
 #ifndef USHRT_MAX
   } OVERCHAT_IP;
 #endif /*OVERCHAT_IPV6*/
 
+/*
+  These binary flags are used by blakeMessage
+*/
+#define BLAKEMESSAGE_FLAGS1_NOTICE (1) /* Notice, such as away, do NOT auto reply to any message marked as a notice! */
+
 struct blake_ver_t {                 /* Generic version number type */
   blake_word8_t major, minor, patch;
 };
 struct blakeMessage {
   blake_byte_t username[OVERCHAT_NICK_LIMIT];
   blake_word8_t cipher; /* 0=plaintext, anything else is a code identifying a cipher */
-  blake_byte_t reserved[128]; /* Should I need to add anything else */
+  blake_word8_t flags1; /* These flags can be found above somewhere, prepended by BLAKEMESSAGE_FLAGS1_ */
+  blake_byte_t reserved[127]; /* Should I need to add anything else */
   /* message follows as extended packet */
 };
 
   initialisation automatically.  However, if you rely on this and don't
   call this function, the code won't port to other platforms.
 */
-BLAKEAPI(bool) blake_Init(void);
+BLAKEAPI(blake_bool_t) blake_Init(void);
 
 /*
   Before a process exits, it is expected to call blake_Cleanup() as a matter
   with this cleanup automatically.  However, if you rely on this and don't
   call this function, the code won't port to other platforms.
 */
-BLAKEAPI(bool) blake_Cleanup(void);
+BLAKEAPI(blake_bool_t) blake_Cleanup(void);
 
 /*
   When blakeError codes are returned from the Blake library and the
   If it fails it will return false, no cleanup is neccersary in this case.
   Normally, cleanup is required with blake_DestroyRecursiveMutant()
 */
-BLAKEAPI(bool) blake_InitRecursiveMutant(recursiveMutant* PMutant);
+BLAKEAPI(blake_bool_t) blake_InitRecursiveMutant(recursiveMutant* PMutant);
 
 /*
   When a recursive mutant has no further use, destroy it with this
   is acceptable or your own numbering system.  but don't get the two systems
   confused!
 */
-BLAKEAPI(enum blakeError) blake_InstallCallback(const int ThreadID, bool IsServer, WORD Code, bool (*UserCallback)(int, const void*, const void*));
+BLAKEAPI(enum blakeError) blake_InstallCallback(const int ThreadID, blake_bool_t IsServer, WORD Code, blake_bool_t (*UserCallback)(int, const void*, const void*));
 
 /*
   Networking
   See other manuals for in depth conversation on this.
   On failure the function returns -1.
 */
-BLAKEAPI(int) network_CreateSocket(bool IPv6, bool Datagram, bool NonBlocking);
+BLAKEAPI(int) network_CreateSocket(blake_bool_t IPv6, blake_bool_t Datagram, blake_bool_t NonBlocking);
 
 
 /*
   returns blakeSuccess then the socket has been successfully connected to
   the server, congratulation.
 */
-BLAKEAPI(enum blakeError) network_Connect(int Socket, bool IPv6, const unsigned short int Port, const OVERCHAT_IP* IP);
+BLAKEAPI(enum blakeError) network_Connect(int Socket, blake_bool_t IPv6, const unsigned short int Port, const OVERCHAT_IP* IP);
 /*
   To allow your program to be called when raw data arrives on a socket,
   a special raw data callback must be installed.  Simply pass the number
   from inside any callback such as those installed by
   network_InstallRawCallback() can deadlock the thread.
 */
-BLAKEAPI(void) blake_PendingLoop(bool RunForever);
+BLAKEAPI(void) blake_PendingLoop(blake_bool_t RunForever);
 /*
   When the pending loop is running in 'RunForever' mode it should
   be cancelled before the process is cleaned up.  To do this
   'RunForever' mode, this function has no effect whatsoever.
 */
 BLAKEAPI(void) blake_CancelPendingLoop(void);
-BLAKEAPI(bool) network_Write(int SocketDesc, const void* Buffer, const size_t BufferSize);
+BLAKEAPI(blake_bool_t) network_Write(int SocketDesc, const void* Buffer, const size_t BufferSize);
 BLAKEAPI(int) network_Read(int SocketDesc, void* Buffer, const size_t BufferSize); /* This works the same way as recv() */
 BLAKEAPI(void) network_LoadIP(OVERCHAT_IP* PDest, OVERCHAT_IP* PSource); /* Copies an IP address, NULL as PSource maybe used to init an IP address */
 BLAKEAPI(void) network_GetIPOnSocket(OVERCHAT_IP* PDest, int SocketDesc); /* Loads the IP holder with the IP when given the socket descriptor for the user */
 BLAKEAPI(unsigned short int) network_HostToNetShort(unsigned short int Value);
 BLAKEAPI(unsigned long int) network_NetToHostLong(unsigned long int Value); /* Change byte order from network */
 BLAKEAPI(unsigned short int) network_NetToHostShort(unsigned short int Value);
-BLAKEAPI(bool) network_WriteString(int SocketDesc, const char* Str); /* Writes a string to the socket */
-BLAKEAPI(bool) network_WriteChar(int SocketDesc, char Char); /* Faster if you only have one byte to write */
+BLAKEAPI(blake_bool_t) network_WriteString(int SocketDesc, const char* Str); /* Writes a string to the socket */
+BLAKEAPI(blake_bool_t) network_WriteChar(int SocketDesc, char Char); /* Faster if you only have one byte to write */
 
 /*
   This function is for incoming connections to the server.  This
   are required for securing the system against unauthorised clients.  They
   must be correct or later security questions by the server will fail.
 */
-BLAKEAPI(bool) blake_Login(int Sock, const char* Username, const char* Password, enum blakeLang Language, const unsigned char ChallengeDigest[BLAKE_MD5HASHLEN], const enum blakeClientID ClientID, const unsigned long ClientVersion);
+BLAKEAPI(blake_bool_t) blake_Login(int Sock, const char* Username, const char* Password, enum blakeLang Language, const unsigned char ChallengeDigest[BLAKE_MD5HASHLEN], const enum blakeClientID ClientID, const unsigned long ClientVersion);
 /*
   Functions called by the server to make the client "shaddup" occasionally.
   Listen to the server when you receive these packets!  Else the server
   will kill you!
 */
 #ifdef BLAKE_SERVER
-BLAKEAPI(bool) blake_Suspend(int Sock, const unsigned long Seconds); /* if Seconds == 0UL client waits for a resume */
-BLAKEAPI(bool) blake_Resume(int Sock);
+BLAKEAPI(blake_bool_t) blake_Suspend(int Sock, const unsigned long Seconds); /* if Seconds == 0UL client waits for a resume */
+BLAKEAPI(blake_bool_t) blake_Resume(int Sock);
 #endif /*BLAKE_SERVER*/
 
 /*
   knows who you are ;-).  Then pass the message.  The message for the said
   person will be queued for you.  It is also now neccersary to pass a code
   identifiying the encryption cipher the message has been encoded with, note
-  that I recommend plain text is never used over the internet.
+  that I recommend plain text is never used over the internet.  Flags1
+  is usually 0, check the BLAKEMESSAGE_FLAGS1_ flags for more information,
+  always use BLAKEMESSAGE_FLAGS1_NOTICE for notices such as away messages.
 */
-BLAKEAPI(enum blakeError) blake_Msg(int Sock, const char* NickName, const char* Msg, enum blakeCipherID BCID);
+BLAKEAPI(enum blakeError) blake_Msg(int Sock, const char* NickName, const char* Msg, enum blakeCipherID BCID, blake_word8_t Flags1);
 
 /*
   blake_Msg2() is the function which doesn't message a user, it is very
 */
 BLAKEAPI(enum blakeError) blake_IsOnline(int Sock, const char* NickName);
 #ifdef BLAKE_SERVER
-BLAKEAPI(enum blakeError) blake_IsOnlineReply(int Sock, const char* NickName, bool Yes);
+BLAKEAPI(enum blakeError) blake_IsOnlineReply(int Sock, const char* NickName, blake_bool_t Yes);
 #endif /*BLAKE_SERVER*/
 
 /*
 /* Some of the values which are always the same in the above header */
 #define BLAKEDB_HEADER_SIG (0x5692fc33)
 #define BLAKEDB_HEADER_REVISION (3)
-#define BLAKEDB_HEADER_COPYRIGHT "OverChat Database revision 2 (C)2002 Daybo Logic, all rights reserved.  www.daybologic.com/overchat"
+#define BLAKEDB_HEADER_COPYRIGHT "OverChat Database revision 2 (C)2002 Daybo Logic, all rights reserved.  www.overchat.net"
 
 /*
   This type, BLAKE_DATABASE_HANDLE, is a handle which is used to access
   is illegal.
   If the nick is too long the TooLong flag is set.
 */
-BLAKEAPI(bool) blake_NickTest(const char* Nickname, bool* PTooLong, char* PSingleInvalidCharacter);
+BLAKEAPI(blake_bool_t) blake_NickTest(const char* Nickname, blake_bool_t* PTooLong, char* PSingleInvalidCharacter);
 
 /*
   This function works in exactly the same way as the nickname tester but it
   is designed for passwords.
 */
-BLAKEAPI(bool) blake_PassTest(const char* Password, bool* PTooLong, char* PSingleInvalidCharacter);
+BLAKEAPI(blake_bool_t) blake_PassTest(const char* Password, blake_bool_t* PTooLong, char* PSingleInvalidCharacter);
 
 /*
   blake_NickCompare( ) returns true if the nicks are the same false if
   converts to uppercase for the comparision and strips and trailing or
   leading space.
 */
-BLAKEAPI(bool) blake_EmailCompare(const char* Email1, const char* Email2);
+BLAKEAPI(blake_bool_t) blake_EmailCompare(const char* Email1, const char* Email2);
 
 /*
   blake_NickRude( ) returns true if a nickname is considered to be rude.
   that substring using nicks like: fucktard, shitfaced and cuntbreath
   cannot be used.
 */
-BLAKEAPI(bool) blake_NickRude(const char* RudeFileName, const char* Nick);
+BLAKEAPI(blake_bool_t) blake_NickRude(const char* RudeFileName, const char* Nick);
 
 /*
   blake_RandPass( ) returns a password of random length containing
   Reinit is used to determine whether Blake reseeds the random number
   generator.  It takes five seconds to seed the generator.
 */
-BLAKEAPI(enum blakeError) blake_RandPass(char* BufferOut, size_t BuffSize, bool Reinit);
+BLAKEAPI(enum blakeError) blake_RandPass(char* BufferOut, size_t BuffSize, blake_bool_t Reinit);
+
+/*
+  This function normalises nicknames to a consistant state, useful for
+  log files and the like.  "D D    Rp"  will become "ddrp".  The MaxBuffSz
+  must be the size of the buffer 'Normalised'.  'Normalised' must be
+  enough to hold the un-normalised nickname, a buffer of the same size
+  as Nickname is most cases.
+*/
+BLAKEAPI(enum blakeError) blake_NormNick(const char* Nickname, char* Normalised, const size_t MaxBuffSz);
 
 /*
   This function is used to convert a security clearance level into a user
   the function.  Always check the return value before checking values.
   If anything other than blakeSuccess, do not close the handle.
 */
-BLAKEAPI(enum blakeError) blake_ExclusiveFileOpen(const char* FileName, bool NeedWrite, FILE** PHandle);
+BLAKEAPI(enum blakeError) blake_ExclusiveFileOpen(const char* FileName, blake_bool_t NeedWrite, FILE** PHandle);
 
 /*
   This function must only be used on handles returned from
 /*
   Language features (blake_lang.c).
   Use these to help support new languages when they come along rather than
-  using your own strings to decide on the language name.
+  using your own strings to decide on the language name.  New: Portable
+  interface to an external strings file.
 */
 
 /*
 */
 BLAKEAPI(const char*) blake_LangName(enum blakeLang LangCode, enum blakeLang InLanguage);
 
+/*
+  blake_LangSetFile() should be used before calling blake_LangGetString(),
+  it indicates the file which contains the strings in the supported languages
+  the file is an RTTB format file containing plain text files which
+  name the language by the language's two letter code.  Obviously because
+  of the split up between these functions, only one file is supported
+  per process.  Threads can't use different strings.  Strings are cached
+  by Blake and are not re-read unless blake_LangCacheFlush() is called.
+*/
+BLAKEAPI(enum blakeError) blake_LangSetFile(const char* LanguageFile);
+
 /***********************************************************************
   OverChat safe memory allocations section.  Use this in your clients
   or in the server.  The portions of memory are protected unless a direct
   are the same and false if they differ.  It is safe against NULL pointers
   and works in a logical fashion with them
 */
-BLAKEAPI(bool) blake_MD5CompareDigests(const unsigned char Digest0[BLAKE_MD5HASHLEN], const unsigned char Digest1[BLAKE_MD5HASHLEN]);
+BLAKEAPI(blake_bool_t) blake_MD5CompareDigests(const unsigned char Digest0[BLAKE_MD5HASHLEN], const unsigned char Digest1[BLAKE_MD5HASHLEN]);
 
 /*
   The random hash function returns a securely random MD5 hash which is
 BLAKEAPI(enum blakeError) blake_MD5SecureDoublePasswordHash(unsigned char HashOut[BLAKE_MD5HASHLEN], const char* Password, const unsigned char HashIn[BLAKE_MD5HASHLEN]);
 
 /*
-  Checksumming features.  Please use these instead od writing
+  This function returns the official name of a hash from it's code.
+*/
+BLAKEAPI(const char*) blake_HashTypeName(const enum blakeHashType HashType);
+
+/*
+  Checksumming features.  Please use these instead of writing
   your own routines to keep overhead down.  I'm using pointers
   for these, this provides us for expansion for other types
   such as 64-bit support on systems which won't allow us to pass
 */
 BLAKEAPI(unsigned int) blake_GetClientIDString(const enum blakeClientID ClientID, char* PBuffOut, const size_t MaxBuffSz);
 
+/*
+  ***********************************
+  * Blake Benchmarking - testing if *
+  * systems are adequate.           *
+  ***********************************
+*/
+
+/*
+  blake_LoopBenchmarkGetIndex() returns either -1 (clock skew), which means
+  the user changed the clock to an earlier time during the test (in which
+  case the test should be repeated), 0, for a very slow computer which did
+  not complete the test or between 1 and 10, where 10 is the fastest
+  computer.  If the test does not return -1, the result is cached so that
+  time is not wasted if the function is called multiple times during
+  the same execution.  It is recommended that the program save the result
+  in a configuration file to avoid calling this, during program init-
+  ialisation, call blake_LoopBenchmarkSetIndex() with the benchmark you
+  got on the first program execution.  How long this function takes to
+  return depends on the speed of the computer, the maximum time the test
+  is allowed to take is 120 seconds (two minutes), at which time the
+  function returns zero.
+*/
+BLAKEAPI(int) blake_LoopBenchmarkGetIndex(void);
+
+/*
+  blake_LoopBenchmarkSetIndex() is used to initialise the benchmark so
+  that the real benchmark is not performed when it is got by the above
+  function.  A value above 10 will be assumed to be 10.  A warning will
+  be printed to stderr if a value above 10 is used.  The function returns
+  the previous value, which is probally -1, as this is the internal value
+  to represent that the benchmark has not yet been run.  Unless you have
+  called this function before of course.  Calling this function with a
+  value of -1 will allow GetIndex() to run the benchmark again, for real.
+*/
+BLAKEAPI(int) blake_LoopBenchmarkSetIndex(const int OldIndex);
+
+/*
+  ****************************************
+  * NetBuffer, the code which handles    *
+  * packets, probally the most annoying  *
+  * thing I had to code in the entire    *
+  * system.                              *
+  ****************************************
+*/
+
+/*
+  netbuffer_Close() deregisters a socket from the NetBuffer system
+  and then calls network_Close() on the socket.  The socket is no longer
+  valid after this call.  The socket must have been registered earlier
+  with netbuffer_Open().
+*/
+BLAKEAPI(void) netbuffer_Close(int Socket);
+
+/*
+  netbuffer_Push() adds data to a socket in the incoming or outgoing
+  direction.  Of course, it still takes callbacks on the socket to
+  actually do anything with this data.  When a whole packet has been
+  pushed, the NetBuffer object for the socket you are working with
+  calls the Blake packet cracker on your behalf.  Quite frankly, the
+  system is complex, see an example client if you are confused.
+*/
+BLAKEAPI(enum blakeNetBufferError) netbuffer_Push(int Socket, enum blakeNetBufferDirection Direction, const void* Data, const size_t DataSize);
+
+/*
+  netbuffer_Pop() takes data from a socket's managed buffer in either
+  direction it is destined for.  It is expected that this data is then
+  processed/sent to the network depending on direction.  Because of the
+  complexity and crucialness of this activity, it is recommended that
+  the reader refer to an example client to see how this is used.
+*/
+BLAKEAPI(size_t) netbuffer_Pop(int Socket, enum blakeNetBufferDirection, void* Data, const size_t MaxDataSize, enum blakeNetBufferError* PNetError);
+
+/*
+  netbuffer_Open() takes an existing, created socket and constructs
+  a NetBuffer object around it.  This object can then be automatically
+  used with the rest of the netbuffer functions above just by supplying
+  the socket number.  netbuffer_Close() must be called afterwards and
+  that will close the socket as well as destroy the associated internal
+  NetBuffer object for that socket.
+*/
+BLAKEAPI(enum blakeNetBufferError) netbuffer_Open(int Socket);
+
 /* Restore C++ naming */
 #ifdef __cplusplus
   }

blake/blake.ide

Binary file modified.
 #
 # Borland C++ IDE generated makefile
-# Generated 05/08/2002 at 01:31:14 
+# Generated 30/09/02 at 20:10:39 
 #
 .AUTODEPEND
 
 ResLocalOptsAtW32_csblakedlib = 
 BLocalOptsAtW32_csblakedlib = 
 CompOptsAt_csblakedlib = $(CompLocalOptsAtW32_csblakedlib)
-CompInheritOptsAt_csblakedlib = -IC:\BC5\INCLUDE;..\SRC;..\DPCRTLMM;..\DAYBOCRYPT -DBLAKE_AS_DLL;NDEBUG
+CompInheritOptsAt_csblakedlib = -IC:\BC5\INCLUDE;..\SRC;..\DPCRTLMM;..\DAYBOCRYPT;..\NETBUFFER -DBLAKE_AS_DLL;NDEBUG
 LinkerInheritOptsAt_csblakedlib = -x
 LinkerOptsAt_csblakedlib = $(LinkerLocalOptsAtW32_csblakedlib)
 ResOptsAt_csblakedlib = $(ResLocalOptsAtW32_csblakedlib)
 ResLocalOptsAtW32_ssblakedlib = 
 BLocalOptsAtW32_ssblakedlib = 
 CompOptsAt_ssblakedlib = $(CompLocalOptsAtW32_ssblakedlib)
-CompInheritOptsAt_ssblakedlib = -IC:\BC5\INCLUDE;..\SRC;..\DPCRTLMM;..\DAYBOCRYPT -DBLAKE_SERVER;NDEBUG
+CompInheritOptsAt_ssblakedlib = -IC:\BC5\INCLUDE;..\SRC;..\DPCRTLMM;..\DAYBOCRYPT;..\NETBUFFER -DBLAKE_SERVER;NDEBUG
 LinkerInheritOptsAt_ssblakedlib = -x
 LinkerOptsAt_ssblakedlib = $(LinkerLocalOptsAtW32_ssblakedlib)
 ResOptsAt_ssblakedlib = $(ResLocalOptsAtW32_ssblakedlib)
 ResLocalOptsAtW32_ssblakeddlib = 
 BLocalOptsAtW32_ssblakeddlib = 
 CompOptsAt_ssblakeddlib = $(CompLocalOptsAtW32_ssblakeddlib)
-CompInheritOptsAt_ssblakeddlib = -IC:\BC5\INCLUDE;..\SRC;..\DPCRTLMM;..\DAYBOCRYPT -DBLAKE_SERVER
+CompInheritOptsAt_ssblakeddlib = -IC:\BC5\INCLUDE;..\SRC;..\DPCRTLMM;..\DAYBOCRYPT;..\NETBUFFER -DBLAKE_SERVER
 LinkerInheritOptsAt_ssblakeddlib = -x
 LinkerOptsAt_ssblakeddlib = $(LinkerLocalOptsAtW32_ssblakeddlib)
 ResOptsAt_ssblakeddlib = $(ResLocalOptsAtW32_ssblakeddlib)
 
 
 Dep_csblakeddll = \
+   BUILD_CSBLAKE\netbuffer.obj\
+   BUILD_CSBLAKE\blake_netbuffer.obj\
+   BUILD_CSBLAKE\blake_chksum.obj\
    BUILD_CSBLAKE\csblake.res\
    BUILD_CSBLAKE\recursivemutant.obj\
    BUILD_CSBLAKE\criticalinteger.obj\
   $(ILINK32) @&&|
  /v $(IDE_LinkFLAGS32) $(LinkerOptsAt_csblakedlib) $(LinkerInheritOptsAt_csblakedlib) +
 C:\BC5\LIB\c0d32.obj+
+BUILD_CSBLAKE\netbuffer.obj+
+BUILD_CSBLAKE\blake_netbuffer.obj+
+BUILD_CSBLAKE\blake_chksum.obj+
 BUILD_CSBLAKE\recursivemutant.obj+
 BUILD_CSBLAKE\criticalinteger.obj+
 BUILD_CSBLAKE\blakedb.obj+
 BUILD_CSBLAKE\csblake.res
 
 |
+BUILD_CSBLAKE\netbuffer.obj :  ..\netbuffer\netbuffer.cpp
+  $(BCC32) -c @&&|
+ $(CompOptsAt_csblakedlib) $(CompInheritOptsAt_csblakedlib) -o$@ ..\netbuffer\netbuffer.cpp
+|
+
+BUILD_CSBLAKE\blake_netbuffer.obj :  blake_netbuffer.cpp
+  $(BCC32) -c @&&|
+ $(CompOptsAt_csblakedlib) $(CompInheritOptsAt_csblakedlib) -o$@ blake_netbuffer.cpp
+|
+
+BUILD_CSBLAKE\blake_chksum.obj :  blake_chksum.c
+  $(BCC32) -P- -c @&&|
+ $(CompOptsAt_csblakedlib) $(CompInheritOptsAt_csblakedlib) -o$@ blake_chksum.c
+|
+
 BUILD_CSBLAKE\csblake.res :  csblake.rc
   $(BRC32) -R @&&|
  $(IDE_ResFLAGS32) $(ROptsAt_csblakedlib) $(CompInheritOptsAt_csblakedlib)  -FO$@ csblake.rc
 |
 
 Dep_ssblakedlib = \
+   BUILD_SSBLAKE\blake_netbuffer.obj\
+   BUILD_SSBLAKE\blake_chksum.obj\
+   BUILD_SSBLAKE\netbuffer.obj\
    BUILD_SSBLAKE\sbeast.obj\
    BUILD_SSBLAKE\murder_microsoft.obj\
    BUILD_SSBLAKE\btfuck.obj\
 
 ssblake.lib : $(Dep_ssblakedlib)
   $(TLIB) $< $(IDE_BFLAGS) $(BOptsAt_ssblakedlib) @&&|
- -+BUILD_SSBLAKE\sbeast.obj &
+ -+BUILD_SSBLAKE\blake_netbuffer.obj &
+-+BUILD_SSBLAKE\blake_chksum.obj &
+-+BUILD_SSBLAKE\netbuffer.obj &
+-+BUILD_SSBLAKE\sbeast.obj &
 -+BUILD_SSBLAKE\murder_microsoft.obj &
 -+BUILD_SSBLAKE\btfuck.obj &
 -+BUILD_SSBLAKE\recursivemutant.obj &
 -+BUILD_SSBLAKE\blake.obj
 |
 
+BUILD_SSBLAKE\blake_netbuffer.obj :  blake_netbuffer.cpp
+  $(BCC32) -c @&&|
+ $(CompOptsAt_ssblakedlib) $(CompInheritOptsAt_ssblakedlib) -o$@ blake_netbuffer.cpp
+|
+
+BUILD_SSBLAKE\blake_chksum.obj :  blake_chksum.c
+  $(BCC32) -P- -c @&&|
+ $(CompOptsAt_ssblakedlib) $(CompInheritOptsAt_ssblakedlib) -o$@ blake_chksum.c
+|
+
+BUILD_SSBLAKE\netbuffer.obj :  ..\netbuffer\netbuffer.cpp
+  $(BCC32) -c @&&|
+ $(CompOptsAt_ssblakedlib) $(CompInheritOptsAt_ssblakedlib) -o$@ ..\netbuffer\netbuffer.cpp
+|
+
 BUILD_SSBLAKE\sbeast.obj :  res\sbeast.c
   $(BCC32) -P- -c @&&|
  $(CompOptsAt_ssblakedlib) $(CompInheritOptsAt_ssblakedlib) -o$@ res\sbeast.c
 |
 
 Dep_ssblakeddlib = \
+   BUILD_SSBLAKED\netbuffer.obj\
+   BUILD_SSBLAKED\blake_chksum.obj\
+   BUILD_SSBLAKED\blake_netbuffer.obj\
    BUILD_SSBLAKED\recursivemutant.obj\
    BUILD_SSBLAKED\criticalinteger.obj\
    BUILD_SSBLAKED\blakedb.obj\
 
 ssblaked.lib : $(Dep_ssblakeddlib)
   $(TLIB) $< $(IDE_BFLAGS) $(BOptsAt_ssblakeddlib) @&&|
- -+BUILD_SSBLAKED\recursivemutant.obj &
+ -+BUILD_SSBLAKED\netbuffer.obj &
+-+BUILD_SSBLAKED\blake_chksum.obj &
+-+BUILD_SSBLAKED\blake_netbuffer.obj &
+-+BUILD_SSBLAKED\recursivemutant.obj &
 -+BUILD_SSBLAKED\criticalinteger.obj &
 -+BUILD_SSBLAKED\blakedb.obj &
 -+BUILD_SSBLAKED\blake_trace.obj &
 -+BUILD_SSBLAKED\btfuck.obj
 |
 
+BUILD_SSBLAKED\netbuffer.obj :  ..\netbuffer\netbuffer.cpp
+  $(BCC32) -c @&&|
+ $(CompOptsAt_ssblakeddlib) $(CompInheritOptsAt_ssblakeddlib) -o$@ ..\netbuffer\netbuffer.cpp
+|
+
+BUILD_SSBLAKED\blake_chksum.obj :  blake_chksum.c
+  $(BCC32) -P- -c @&&|
+ $(CompOptsAt_ssblakeddlib) $(CompInheritOptsAt_ssblakeddlib) -o$@ blake_chksum.c
+|
+
+BUILD_SSBLAKED\blake_netbuffer.obj :  blake_netbuffer.cpp
+  $(BCC32) -c @&&|
+ $(CompOptsAt_ssblakeddlib) $(CompInheritOptsAt_ssblakeddlib) -o$@ blake_netbuffer.cpp
+|
+
 BUILD_SSBLAKED\recursivemutant.obj :  recursivemutant.c
   $(BCC32) -P- -c @&&|
  $(CompOptsAt_ssblakeddlib) $(CompInheritOptsAt_ssblakeddlib) -o$@ recursivemutant.c

blake/blake.mbt

Binary file modified.
 extern const char __rawimage_btfuck[];
 extern const char __rawimage_murder_microsoft[];
 extern const char __rawimage_sbeast[];
+extern const char __rawimage_coup[];
 #endif /*!RC_INVOKED*/

blake/blake_bench.c

+/*
+  /------------------------------------------------------------------\
+  | Blake's Benchmark Support.                                       |
+  | (C) Copyright 2002 Daybo Logic, all rights reserved.             |
+  | maintainer == http://www.daybologic.co.uk/mailddrp (DDRP)        |
+  \------------------------------------------------------------------/
+*/
+
+#define BLAKE_SOURCE
+#include "overchat_config.h" /* Master project configuration */
+#include <time.h>
+#include <limits.h>
+#include <stdio.h>
+#ifdef HDRSTOP
+# pragma hdrstop
+#endif /*HDRSTOP*/
+
+#include "ddrptype.h"
+#include "blake.h"
+/*-------------------------------------------------------------------------*/
+static struct {
+  struct {
+    int index;
+  } loop; /* Loop benchmark variables */
+  BLAKE_MUTANT_HANDLE lock; /* Must be locked before any of the above data is accessed */
+} data;
+
+static void InitLoopBenchmark(void);
+
+#define lock() blake_LockMutant(data.lock)
+#define unlock() blake_UnlockMutant(data.lock)
+/*-------------------------------------------------------------------------*/
+bool blake_BenchInit()
+{
+  data.lock = blake_CreateMutant();
+  if ( data.lock != BLAKE_INVALID_HANDLE ) {
+    InitLoopBenchmark(); /* Initialise variable for the looping benchmark */
+    return true; /* Initialisation successful */
+  }
+  return false;
+}
+/*-------------------------------------------------------------------------*/
+void blake_BenchCleanup()
+{
+  if ( data.lock != BLAKE_INVALID_HANDLE ) {
+    blake_DestroyMutant(data.lock);
+    data.lock = BLAKE_INVALID_HANDLE;
+  }
+}
+/*-------------------------------------------------------------------------*/
+bool blake_BenchIsInited()
+{
+  return ( data.lock == BLAKE_INVALID_HANDLE ) ? (false) : (true);
+}
+/*-------------------------------------------------------------------------*/
+static void InitLoopBenchmark()
+{
+  data.loop.index = -1; /* Mark as waiting for loop benchmark to run */
+}
+/*-------------------------------------------------------------------------*/
+BLAKEAPI(int) blake_LoopBenchmarkGetIndex()
+{
+  time_t start, stop;
+  unsigned int i;
+  int retval = -1;
+
+  lock();
+  if ( data.loop.index != -1 ) /* Cached result already? */
+    retval = data.loop.index; /* Use this to save time */
+  unlock();
+
+  if ( retval != -1 ) return retval; /* Use cached value */
+
+  time(&start); /* Record time we start */
+
+  /* Run the mental loop */
+  for ( i = 0U; i < 10000000 ; i++ ) {
+    time(&stop); /* Keep recording possible stopping time */
+    if ( (stop - start) >= 120 ) break; /* Far too long */
+  }
+
+  if ( stop < start ) /* Clock went backward! */
+    return retval; /* Return -1 (clock skew) */
+
+  /* Here are our list of preset levels of performance */
+       if ( (stop - start) < 2 ) retval = 10;
+  else if ( (stop - start) < 4 ) retval = 9;
+  else if ( (stop - start) < 5 ) retval = 8;
+  else if ( (stop - start) < 7 ) retval = 7;
+  else if ( (stop - start) < 10 ) retval = 6;
+  else if ( (stop - start) < 15 ) retval = 5;
+  else if ( (stop - start) < 20 ) retval = 4;
+  else if ( (stop - start) < 30 ) retval = 3;
+  else if ( (stop - start) < 60 ) retval = 2;
+  else if ( (stop - start) < 120 ) retval = 1;
+  else retval = 0; /* Test didn't finish within 120 seconds */
+
+  /* Cache result */
+  lock();
+  data.loop.index = retval;
+  unlock();
+  return retval;
+}
+/*-------------------------------------------------------------------------*/
+BLAKEAPI(int) blake_LoopBenchmarkSetIndex(const int OldIndex)
+{
+  int oldIndex;
+
+  lock();
+  oldIndex = data.loop.index; /* Save old index */
+  data.loop.index = OldIndex; /* Stop user index */
+  if ( data.loop.index > 10 ) { /* Too great? */
+    data.loop.index = 10; /* Force correction */
+    unlock();
+    fprintf(stderr, "Warning: Tried set previous index of %u, values above 10 are capped!\n", OldIndex); /* Might wan to use Blake logging in the future, correct documentation in blake.h if you change this! */
+  }
+  else
+    unlock();
+
+  printf("DEBUG: OldIndex=%d, oldIndex=%d\n", OldIndex, oldIndex);
+
+  return oldIndex; /* Return the old internal index */
+}
+/*-------------------------------------------------------------------------*/

blake/blake_bench.h

+/*
+  Internal interface to Blake's benchmarking code
+
+  (C) 2003 Daybo Logic, all rights reserved.
+  Don't include this header in non-Blake code.
+*/
+
+#ifndef __INC_BLAKE_BENCH_H
+#define __INC_BLAKE_BENCH_H
+
+#ifndef BLAKE_SOURCE
+# error ("Sod off, this header ain't for you")
+#endif /*!BLAKE_SOURCE*/
+
+OVERCHAT_C_IN_CPP bool blake_BenchInit(OVERCHAT_PROTOTYPE_VOID);
+OVERCHAT_C_IN_CPP void blake_BenchCleanup(OVERCHAT_PROTOTYPE_VOID);
+OVERCHAT_C_IN_CPP bool blake_BenchIsInited(OVERCHAT_PROTOTYPE_VOID);
+
+#endif /*!__INC_BLAKE_BENCH_H*/
 /* Before changing any of the callbacks make sure the mutant is locked */
 static struct {
   recursiveMutant* mutantPtr;
-  bool (*suspend)(int Sock, struct blakeSuspend* PBlakeSuspend, const void* Nothing);
-  bool (*resume)(int Sock, struct blakeResume* PResume, const void* Nothing);
-  bool (*challenge)(int Sock, struct blakeChallenge* PChallenge, const void* Nothing);
-  bool (*goterror)(int Sock, struct blakeGotError* PGotError, const void* Nothing);
-  bool (*listresponse)(int Sock, struct blakeListResponse* PListResponse, const void* Nothing);
-  bool (*whoisinfo)(int Sock, struct blakeWhoisInfo* PWhoisInfo, const void* Nothing);
-  bool (*versioned)(int Sock, struct blakeVersioned* PVersionVersioned, const void* Nothing);
-  bool (*super)(int Sock, struct blakeSuper* PSuper, const void* Nothing);
-  bool (*killed)(int Sock, struct blakeKilled* PKilled, const char* Reason);
-  bool (*chumsignon)(int Sock, struct blakeChumSignon* PChumSignon, const void* Nothing);
-  bool (*chumsignoff)(int Sock, struct blakeChumSignoff* PChumSignoff, const void* Nothing);
-  bool (*chumidle)(int Sock, struct blakeChumIdle* PChumIdle, const void* Nothing);
-  bool (*loginreply)(int Sock, struct blakeLoginReply* PLoginResponse, const void* Nothing);
-  bool (*isonlinereply)(int Sock, struct blakeIsOnlineReply* PIsOnlineReply, const void* Nothing);
-  bool (*registerreply)(int Sock, struct blakeRegisterReply* PRegisterReply, const void* Nothing);
+  blake_bool_t (*suspend)(int Sock, struct blakeSuspend* PBlakeSuspend, const void* Nothing);
+  blake_bool_t (*resume)(int Sock, struct blakeResume* PResume, const void* Nothing);
+  blake_bool_t (*challenge)(int Sock, struct blakeChallenge* PChallenge, const void* Nothing);
+  blake_bool_t (*goterror)(int Sock, struct blakeGotError* PGotError, const void* Nothing);
+  blake_bool_t (*listresponse)(int Sock, struct blakeListResponse* PListResponse, const void* Nothing);
+  blake_bool_t (*whoisinfo)(int Sock, struct blakeWhoisInfo* PWhoisInfo, const void* Nothing);
+  blake_bool_t (*versioned)(int Sock, struct blakeVersioned* PVersionVersioned, const void* Nothing);
+  blake_bool_t (*super)(int Sock, struct blakeSuper* PSuper, const void* Nothing);
+  blake_bool_t (*killed)(int Sock, struct blakeKilled* PKilled, const char* Reason);
+  blake_bool_t (*chumsignon)(int Sock, struct blakeChumSignon* PChumSignon, const void* Nothing);
+  blake_bool_t (*chumsignoff)(int Sock, struct blakeChumSignoff* PChumSignoff, const void* Nothing);
+  blake_bool_t (*chumidle)(int Sock, struct blakeChumIdle* PChumIdle, const void* Nothing);
+  blake_bool_t (*loginreply)(int Sock, struct blakeLoginReply* PLoginResponse, const void* Nothing);
+  blake_bool_t (*isonlinereply)(int Sock, struct blakeIsOnlineReply* PIsOnlineReply, const void* Nothing);
+  blake_bool_t (*registerreply)(int Sock, struct blakeRegisterReply* PRegisterReply, const void* Nothing);
 
-  bool (*login)(int Sock, struct blakeLogin* PLogin, const void* Nothing);
-  bool (*superrequest)(int Sock, struct blakeSuperRequest* PSuperRequest, const void* Nothing);
-  bool (*addwanker)(int Sock, struct blakeAddWanker* PAddWanker, const void* Nothing);
-  bool (*notwanker)(int Sock, struct blakeNotWanker* PNotWanker, const void* Nothing);
-  bool (*joinchat)(int Sock, struct blakeJoinChat* PJoinChat, const void* Nothing);
-  bool (*list)(int Sock, struct blakeList* PList, const void* Nothing);
-  bool (*killuser)(int Sock, struct blakeKillUser* PKillUser, const char* Reason);
-  bool (*killchat)(int Sock, struct blakeKillChat* PKillChat, const void* Nothing);
-  bool (*kick)(int Sock, struct blakeKick* PKick, const void* Nothing);
-  bool (*reserved0)(int Sock, struct blakeReserved0* PReserved0, const void* Nothing);
-  bool (*nonsense0)(int Sock, struct blakeNonsense0* PNonsense0, const void* Nothing);
-  bool (*version)(int Sock, struct blakeVersion* PVersion, const void* Nothing);
-  bool (*message)(int Sock, struct blakeMessage* PMessage, const char* IMMessage);
-  bool (*message2)(int Sock, struct blakeMessage2* PMessage2, const char* Command);
-  bool (*chatmsg)(int Sock, struct blakeChatMsg* PChatMsg, const char* ChatMessage);
-  bool (*whois)(int Sock, struct blakeWhois* PWhois, const void* Nothing);
-  bool (*undocumented0)(int Sock, struct blakeUndocumented0* PUndocumented0, const void* Nothing);
-  bool (*remoteshutdown)(int Sock, struct blakeRemoteShutdown* PRemoteShutdown, const void* Nothing);
-  bool (*chumadd)(int Sock, struct blakeChumAdd* PChumAdd, const void* Nothing);
-  bool (*chumremove)(int Sock, struct blakeChumRemove* PChumRemove, const void* Nothing);
-  bool (*idle)(int Sock, struct blakeIdle* PIdle, const void* Nothing);
-  bool (*isonline)(int Sock, struct blakeIsOnline* PIsOnline, const void* Nothing);
-  bool (*Register)(int Sock, struct blakeRegister* PRegister, const void* Nothing); /* "register" is a keyword, use Register instead */
+  blake_bool_t (*login)(int Sock, struct blakeLogin* PLogin, const void* Nothing);
+  blake_bool_t (*superrequest)(int Sock, struct blakeSuperRequest* PSuperRequest, const void* Nothing);
+  blake_bool_t (*addwanker)(int Sock, struct blakeAddWanker* PAddWanker, const void* Nothing);
+  blake_bool_t (*notwanker)(int Sock, struct blakeNotWanker* PNotWanker, const void* Nothing);
+  blake_bool_t (*joinchat)(int Sock, struct blakeJoinChat* PJoinChat, const void* Nothing);
+  blake_bool_t (*list)(int Sock, struct blakeList* PList, const void* Nothing);
+  blake_bool_t (*killuser)(int Sock, struct blakeKillUser* PKillUser, const char* Reason);
+  blake_bool_t (*killchat)(int Sock, struct blakeKillChat* PKillChat, const void* Nothing);
+  blake_bool_t (*kick)(int Sock, struct blakeKick* PKick, const void* Nothing);
+  blake_bool_t (*reserved0)(int Sock, struct blakeReserved0* PReserved0, const void* Nothing);
+  blake_bool_t (*nonsense0)(int Sock, struct blakeNonsense0* PNonsense0, const void* Nothing);
+  blake_bool_t (*version)(int Sock, struct blakeVersion* PVersion, const void* Nothing);
+  blake_bool_t (*message)(int Sock, struct blakeMessage* PMessage, const char* IMMessage);
+  blake_bool_t (*message2)(int Sock, struct blakeMessage2* PMessage2, const char* Command);
+  blake_bool_t (*chatmsg)(int Sock, struct blakeChatMsg* PChatMsg, const char* ChatMessage);
+  blake_bool_t (*whois)(int Sock, struct blakeWhois* PWhois, const void* Nothing);
+  blake_bool_t (*undocumented0)(int Sock, struct blakeUndocumented0* PUndocumented0, const void* Nothing);
+  blake_bool_t (*remoteshutdown)(int Sock, struct blakeRemoteShutdown* PRemoteShutdown, const void* Nothing);
+  blake_bool_t (*chumadd)(int Sock, struct blakeChumAdd* PChumAdd, const void* Nothing);
+  blake_bool_t (*chumremove)(int Sock, struct blakeChumRemove* PChumRemove, const void* Nothing);
+  blake_bool_t (*idle)(int Sock, struct blakeIdle* PIdle, const void* Nothing);
+  blake_bool_t (*isonline)(int Sock, struct blakeIsOnline* PIsOnline, const void* Nothing);
+  blake_bool_t (*Register)(int Sock, struct blakeRegister* PRegister, const void* Nothing); /* "register" is a keyword, use Register instead */
 } callbacks;
 /*-------------------------------------------------------------------------*/
 bool blake_cb_Init()
   return status;
 }
 /*-------------------------------------------------------------------------*/
-BLAKEAPI(enum blakeError) blake_InstallCallback(const int ThreadID, bool IsServer, WORD Code, bool (*UserCallback)(int, const void*, const void*))
+BLAKEAPI(enum blakeError) blake_InstallCallback(const int ThreadID, blake_bool_t IsServer, WORD Code, blake_bool_t (*UserCallback)(int, const void*, const void*))
 {
   enum blakeError ret = blakeSuccess;
   blake_cb_AquireLock(ThreadID);
   if ( IsServer ) {
     switch ( (enum blakeServerCodes)Code ) {
       case bscsuspend : {
-        callbacks.suspend = (bool (*)(int Sock, struct blakeSuspend*, const void*))UserCallback;
+        callbacks.suspend = (blake_bool_t (*)(int Sock, struct blakeSuspend*, const void*))UserCallback;
         break;
       }
       case bscresume : {
-        callbacks.resume = (bool (*)(int Sock, struct blakeResume*, const void*))UserCallback;
+        callbacks.resume = (blake_bool_t (*)(int Sock, struct blakeResume*, const void*))UserCallback;
         break;
       }
       case bscchallenge : {
-        callbacks.challenge = (bool (*)(int Sock, struct blakeChallenge*, const void*))UserCallback;
+        callbacks.challenge = (blake_bool_t (*)(int Sock, struct blakeChallenge*, const void*))UserCallback;
         break;
       }
       case bscgoterror : {
-        callbacks.goterror = (bool (*)(int Sock, struct blakeGotError*, const void*))UserCallback;
+        callbacks.goterror = (blake_bool_t (*)(int Sock, struct blakeGotError*, const void*))UserCallback;
         break;
       }
       case bsclist_response : {}
       case bscwhois_info : {
-        callbacks.whoisinfo = (bool (*)(int Sock, struct blakeWhoisInfo*, const void*))UserCallback;
+        callbacks.whoisinfo = (blake_bool_t (*)(int Sock, struct blakeWhoisInfo*, const void*))UserCallback;
         break;
       }
       case bscversioned : {}
       case bscsuper : {
-        callbacks.super = (bool (*)(int Sock, struct blakeSuper*, const void*))UserCallback;
+        callbacks.super = (blake_bool_t (*)(int Sock, struct blakeSuper*, const void*))UserCallback;
         break;
       }
       case bsckilled : {
-        callbacks.killed = (bool (*)(int Sock, struct blakeKilled*, const char* Reason))UserCallback;
+        callbacks.killed = (blake_bool_t (*)(int Sock, struct blakeKilled*, const char* Reason))UserCallback;
         break;
       }
       case bscchum_signon : {}
       case bscchum_signoff : {}
       case bscchum_idle : {}
       case bscloginreply : {
-        callbacks.loginreply = (bool (*)(int Sock, struct blakeLoginReply*, const void*))UserCallback;
+        callbacks.loginreply = (blake_bool_t (*)(int Sock, struct blakeLoginReply*, const void*))UserCallback;
         break;
       }
       case bscisonlinereply : {
-        callbacks.isonlinereply = (bool (*)(int Sock, struct blakeIsOnlineReply*, const void*))UserCallback;
+        callbacks.isonlinereply = (blake_bool_t (*)(int Sock, struct blakeIsOnlineReply*, const void*))UserCallback;
         break;
       }
       case bscregisterreply : {
-        callbacks.registerreply = (bool (*)(int Sock, struct blakeRegisterReply*, const void*))UserCallback;
+        callbacks.registerreply = (blake_bool_t (*)(int Sock, struct blakeRegisterReply*, const void*))UserCallback;
         break;
       }
       default : {
   else { /* Client code */
     switch ( (enum blakeClientCodes)Code ) {
       case bcclogin : {
-        callbacks.login = (bool (*)(int Sock, struct blakeLogin*, const void*))UserCallback;
+        callbacks.login = (blake_bool_t (*)(int Sock, struct blakeLogin*, const void*))UserCallback;
         break;
       }
       case bccsuper_request : {
-        callbacks.superrequest = (bool (*)(int sock, struct blakeSuperRequest*, const void*))UserCallback;
+        callbacks.superrequest = (blake_bool_t (*)(int sock, struct blakeSuperRequest*, const void*))UserCallback;
         break;
       }
       case bccadd_wanker : {}
       case bccjoin_chat : {}
       case bcclist : {}
       case bcckilluser : {
-        callbacks.killuser = (bool (*)(int Sock, struct blakeKillUser*, const char* Reason))UserCallback;
+        callbacks.killuser = (blake_bool_t (*)(int Sock, struct blakeKillUser*, const char* Reason))UserCallback;
         break;
       }
       case bcckillchat : {}
       case bccnonsense0 : {}
       case bccversion : {}
       case bccmessage : {
-        callbacks.message = (bool (*)(int Sock, struct blakeMessage*, const char* IMMessage))UserCallback;
+        callbacks.message = (blake_bool_t (*)(int Sock, struct blakeMessage*, const char* IMMessage))UserCallback;
         break;
       }
       case bccmessage2 : {
-        callbacks.message2 = (bool (*)(int Sock, struct blakeMessage2*, const char* Command))UserCallback;
+        callbacks.message2 = (blake_bool_t (*)(int Sock, struct blakeMessage2*, const char* Command))UserCallback;
         break;
       }
       case bccchatmsg : {
-        callbacks.chatmsg = (bool (*)(int Sock, struct blakeChatMsg*, const char* ChatMessage))UserCallback;
+        callbacks.chatmsg = (blake_bool_t (*)(int Sock, struct blakeChatMsg*, const char* ChatMessage))UserCallback;
         break;
       }
       case bccwhois : {
-        callbacks.whois = (bool (*)(int Sock, struct blakeWhois*, const void*))UserCallback;
+        callbacks.whois = (blake_bool_t (*)(int Sock, struct blakeWhois*, const void*))UserCallback;
         break;
       }
       case bccundocumented0 : {}
       case bccchum_remove : {}
       case bccidle : {}
       case bccisonline : {
-        callbacks.isonline = (bool (*)(int Sock, struct blakeIsOnline*, const void*))UserCallback;
+        callbacks.isonline = (blake_bool_t (*)(int Sock, struct blakeIsOnline*, const void*))UserCallback;
         break;
       }
       case bccregister : {
-        callbacks.Register = (bool (*)(int Sock, struct blakeRegister*, const void* Nothing))UserCallback;
+        callbacks.Register = (blake_bool_t (*)(int Sock, struct blakeRegister*, const void* Nothing))UserCallback;
         break;
       }
       default : {
   * Maintainer: Overlord@DayboLogic.co.uk                               *
   *---------------------------------------------------------------------*
 */
-
+
 #define BLAKE_SOURCE
 #include "overchat_config.h" /* Main project configuration */
 #include <limits.h>
 #include "blake_main.h" /* Internal functions for Blake */
 /*-------------------------------------------------------------------------*/
 /*-------------------------------------------------------------------------*/
-BLAKEAPI(enum blakeError) blake_ExclusiveFileOpen(const char* FileName, bool NeedWrite, FILE** PHandle)
-{
+BLAKEAPI(enum blakeError) blake_ExclusiveFileOpen(const char* FileName, blake_bool_t NeedWrite, FILE** PHandle)
+{
   int fd;
   FILE* fsp = NULL;
 
   *PHandle = fsp;
   if ( fd == -1 )
     return blakeExclusiveFileFailure;
-  return blakeSuccess;
+  return blakeSuccess;
 }
 /*-------------------------------------------------------------------------*/
 BLAKEAPI(void) blake_ExclusiveFileClose(FILE* Handle)
-{
+{
   if ( Handle ) {
     /* I don't think I have to unlock the file in UNIX, just close the handle and I should be finished with it */
 #ifndef __UNIX__ /* Not UNIX */
 # endif
 #endif
     fclose(Handle);
-  }
+  }
 }
 /*-------------------------------------------------------------------------*/

blake/blake_hashes.c

   return HashOut; /* For use in expressions */
 }
 /*-------------------------------------------------------------------------*/
-BLAKEAPI(bool) blake_MD5CompareDigests(const unsigned char Digest0[BLAKE_MD5HASHLEN], const unsigned char Digest1[BLAKE_MD5HASHLEN])
+BLAKEAPI(blake_bool_t) blake_MD5CompareDigests(const unsigned char Digest0[BLAKE_MD5HASHLEN], const unsigned char Digest1[BLAKE_MD5HASHLEN])
 {
   return daybocrypt_MD5CompareDigests(Digest0, Digest1);
 }
   return blakeSuccess;
 }
 /*-------------------------------------------------------------------------*/
+BLAKEAPI(const char*) blake_HashTypeName(const enum blakeHashType HashType)
+{
+  static const char def[] = "UNKNOWN";
+  static const char* hashTypes[] = {
+    "RSA Message Digest Algorithm 5",
+    "RSA Double MDA 5",
+    "NSA Secure Hash Algorithm",
+    "NSA SHA-1"
+  };
+
+  if ( HashType >= sizeof(hashTypes)/sizeof(hashTypes[0]) )
+    return def;
+
+  return hashTypes[HashType];
+}
 /*-------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------*/

blake/blake_lang.c

   Blake language module.
   Blake, OverChat system.
   (C)2002 Daybo Logic, all rights reserved.
-  Maintained by David Duncan Ross Palmer <Overlord@DayboLogic.co.uk>
+  Maintained by David Duncan Ross Palmer <www.daybologic.co.uk/mailddrp>
   http://www.daybologic.co.uk/overchat
 */
 
 #include <time.h>
 #include <stdio.h>
 #include <stddef.h>
+#include <string.h>
 
 #ifdef HDRSTOP
 # pragma hdrstop
 #endif /*HDRSTOP*/
 
 #include "ddrptype.h"
+#include "dpcrtlmm.h"
+#include "rttb.h" /* Archive library */
 #include "blake.h"
+#include "stopcodes.h"
+/*-------------------------------------------------------------------------*/
+struct S_CACHED_STRING { /* One cached string */
+  int id; /* The string's ID (index into language file) */
+  char* ptr; /* The string */
+};
+
+struct S_CACHED_STRING_PERLANG { /* One language of cached strings */
+  int n; /* The number of strings */
+  struct S_CACHED_STRING** pstrings; /* The array of strings */
+};
+
+static struct {
+  BLAKE_MUTANT_HANDLE lock; /* Lock before messing with this data */
+  PS_DPCRTLMM_BLOCKDESCARRAY mem; /* For local memory allocation */
+  char* languageFile; /* Filename of language file for this process */
+  RTTB_HANDLE languageFileHandle[OVERCHAT_NUMLANGUAGES]; /* Handle of language file (if open) */
+  struct S_CACHED_STRING_PERLANG stringsPerLang[OVERCHAT_NUMLANGUAGES];
+} data;
+
+static bool inited;
+
+static const char* blake_internal_LangFileName(enum blakeLang LangCode);
+static enum blakeError blake_internal_LangCacheFlush(void); /* Flush cache without mutant locking */
+static const char* blake_internal_IsStringLoaded(enum blakeLang Language, int StringId); /* Determine if a specific string in a particular language is in the cache */
+static const char* blake_internal_LoadString(int StringID, enum blakeLang Language, enum blakeError* PBlakeErrorOut); /* Load a string into the cache, expects it not to be in the cache!  Use with care */
+static bool blake_internal_Open(enum blakeLang Language, bool OpenMode); /* Open the language file (or close it) */
+/*-------------------------------------------------------------------------*/
+bool blake_LangIsInited()
+{
+  return inited;
+}
+/*-------------------------------------------------------------------------*/
+bool blake_LangInit()
+{
+  if ( !inited ) {
+    /* Set up lock */
+    data.lock = blake_CreateMutant();
+    if ( data.lock == BLAKE_INVALID_HANDLE )
+    return inited; /* Return false =( */
+
+    /* Set up memory controls */
+    data.mem = dpcrtlmm_CreateBlockArray();
+    if ( !data.mem ) { /* Failed */
+      /* Cleaning up */
+      blake_DestroyMutant(data.lock);
+      return inited; /* false */
+    }
+
+    inited = true;
+  }
+  return inited;
+}
+/*-------------------------------------------------------------------------*/
+void blake_LangCleanup()
+{
+  if ( inited ) {
+    if ( data.lock != BLAKE_INVALID_HANDLE ) {
+      unsigned int i;
+
+      blake_LockMutant(data.lock);
+
+      if ( data.languageFile ) {
+        dpcrtlmm_Free(data.mem, data.languageFile); /* Release the language string */
+        data.languageFile = NULL;
+      }
+
+      /* Clean up all the RTTB handles */
+      for ( i = 0U; i < sizeof(data.languageFileHandle)/sizeof(data.languageFileHandle[0]); i++ ) {
+        if ( data.languageFileHandle[i] ) {
+          rttb_fclose(data.languageFileHandle[i]);
+          data.languageFileHandle[i] = 0;
+        }
+      }
+
+      blake_internal_LangCacheFlush(); /* Clean up cached strings */
+
+      dpcrtlmm_DestroyBlockArray(data.mem);
+      data.mem = NULL;
+
+      blake_UnlockMutant(data.lock);
+      blake_DestroyMutant(data.lock);
+      data.lock = BLAKE_INVALID_HANDLE;
+    }
+    inited = false;
+  }
+}
 /*-------------------------------------------------------------------------*/
 BLAKEAPI(const char*) blake_LangShortcut(enum blakeLang LangCode)
 {
   static const char* languages[] = {
     "en", "fr", "sp", "ge", "it", "po"
   };
-  
+
   if ( LangCode >= sizeof(languages)/sizeof(languages[0]) )
     return NULL;
-    
+
+  return languages[LangCode];
+}
+/*-------------------------------------------------------------------------*/
+static const char* blake_internal_LangFileName(enum blakeLang LangCode)
+{
+  static const char* languages[] = {
+    "english.txt",
+    "french.txt",
+    "spanish.txt",
+    "german.txt",
+    "italian.txt",
+    "portuguese.txt"
+  };
+
+  if ( LangCode >= sizeof(languages)/sizeof(languages[0]) )
+    return NULL;
+
   return languages[LangCode];
 }
 /*-------------------------------------------------------------------------*/
   static const char* unknown[] = {
     "Unknown language", "Inconnu langage", "Desconocido lenguaje", "Unbekannte Sprache", "Sconosciuto linguaggio", "Desconhecida lingua"
   };
-  
+
   switch ( InLanguage ) {
     case langEnglish : {
       if ( LangCode < sizeof(enLangs)/sizeof(enLangs[0]) )
   return unknown[langEnglish];
 }
 /*-------------------------------------------------------------------------*/
+BLAKEAPI(enum blakeError) blake_LangSetFile(const char* LanguageFile)
+{
+  enum blakeError err = blakeSuccess;
+
+  if ( !inited ) return blakeNotStarted;
+
+  blake_LockMutant(data.lock);
+  blake_internal_LangCacheFlush(); /* Flush all previous strings now the filename is being changed */
+
+  if ( data.languageFile ) { /* Have a string already? */
+    dpcrtlmm_Free(data.mem, data.languageFile);
+    data.languageFile = NULL;
+  }
+
+  if ( LanguageFile && LanguageFile[0] ) {
+    data.languageFile = dpcrtlmm_Alloc(data.mem, strlen(LanguageFile)+1);
+    if ( data.languageFile )
+      strcpy(data.languageFile, LanguageFile);
+    else
+      err = blakeNotEnoughMem;
+  }
+  else
+    err = blakeInvalidParam;
+
+  blake_UnlockMutant(data.lock);
+  return err;
+}
+/*-------------------------------------------------------------------------*/
+BLAKEAPI(const char*) blake_LangGetString(
+  int StringID, /* This depends on the caller completely */
+  enum blakeLang Language, /* Only Blake supported languages */
+  enum blakeError* PBlakeErrorOut /* Optional error code recovery */
+)
+{
+  const char* ptr;
+
+  blake_LockMutant(data.lock);
+  ptr = blake_internal_IsStringLoaded(Language, StringID);
+  if ( !ptr ) /* Not in cache, load... */
+    ptr = blake_internal_LoadString(Language, StringID, PBlakeErrorOut);
+
+  blake_UnlockMutant(data.lock);
+  return ptr;
+}
+/*-------------------------------------------------------------------------*/
+BLAKEAPI(enum blakeError) blake_LangCacheFlush()
+{
+  enum blakeError err = blakeNotStarted;
+  if ( !inited ) return err;
+
+  blake_LockMutant(data.lock);
+  err = blake_internal_LangCacheFlush();
+  blake_UnlockMutant(data.lock);
+
+  return err;
+}
+/*-------------------------------------------------------------------------*/
+static enum blakeError blake_internal_LangCacheFlush()
+{
+  int currLang;
+
+  for ( currLang = 0; currLang < OVERCHAT_NUMLANGUAGES; currLang++ ) {
+    int oldn = data.stringsPerLang[currLang].n;
+    int i = oldn;
+    while ( i ) {
+      dpcrtlmm_Free(data.mem, data.stringsPerLang[currLang].pstrings[i]->ptr); /* Release a string */
+      dpcrtlmm_Free(data.mem, data.stringsPerLang[currLang].pstrings[i]); /* Release an entry */
+      data.stringsPerLang[currLang].n--;
+      i--;
+    }
+    if ( oldn ) {
+      dpcrtlmm_Free(data.mem, data.stringsPerLang[currLang].pstrings); /* Release array of entries */
+      data.stringsPerLang[currLang].pstrings = NULL;
+    }
+  }
+  return blakeSuccess;
+}
+/*-------------------------------------------------------------------------*/
+static const char* blake_internal_IsStringLoaded(enum blakeLang Language, int StringId)
+{
+  int i;
+  const char* ptr = NULL;
+
+  if ( Language >= OVERCHAT_NUMLANGUAGES ) {
+    blake_word32_t params[2];
+    params[0] = (blake_word32_t)blake_Here(0);
+    params[1] = OVERCHAT_NUMLANGUAGES;
+    params[2] = Language;
+    PANIC(BLAKESTOP_DDRP_LANG_UNKNOWN, sizeof(params)/sizeof(params[0]), params);
+  }
+
+  for ( i = 0; i < data.stringsPerLang[Language].n; i++ ) {
+    if ( data.stringsPerLang[Language].pstrings[i]->id == StringId )
+      ptr = data.stringsPerLang[Language].pstrings[i]->ptr; /* Found! */
+  }
+
+  return ptr;
+}
+/*-------------------------------------------------------------------------*/
+static const char* blake_internal_LoadString(int StringID, enum blakeLang Language, enum blakeError* PBlakeErrorOut)
+{
+  char lineBuff[8192]; /* Maximum possible line length we will support */
+
+  struct S_CACHED_STRING** newptr = dpcrtlmm_Realloc(data.mem, data.stringsPerLang[Language].pstrings, (++data.stringsPerLang[Language].n) * sizeof(struct S_CACHED_STRING**));
+  if ( newptr )
+    data.stringsPerLang[Language].pstrings = newptr;
+  else {
+    if ( PBlakeErrorOut )
+      *PBlakeErrorOut = blakeNotEnoughMem;
+    return NULL;
+  }
+
+  /* OK, now we have space to load it, ensure the language file is open */
+  if ( !blake_internal_Open(Language, true) ) {
+    if ( PBlakeErrorOut )
+      *PBlakeErrorOut = blakeArchivedFileError;
+    return NULL;
+  }
+
+  /* Let's read the the lines until we get to the correct one */
+  
+}
+/*-------------------------------------------------------------------------*/
+static bool blake_internal_Open(enum blakeLang Language, bool OpenMode)
+{
+  if ( OpenMode ) {
+    if ( !data.languageFileHandle[Language] && data.languageFile ) {
+      RTTB_ERROR err;
+      data.languageFileHandle[Language] = rttb_fopen(data.languageFile, blake_internal_LangFileName(Language), "rt", 1, &err);
+      if ( err == RTTB_ERROR_NOERROR )
+        return true;
+      else
+        data.languageFileHandle[Language] = 0;
+    }
+  }
+  else { /* CloseMode */
+    if ( data.languageFileHandle[Language] ) {
+      RTTB_ERROR err = rttb_fclose(data.languageFileHandle[Language]);
+      if ( err == RTTB_ERROR_NOERROR ) {
+        data.languageFileHandle[Language] = 0;
+        return true;
+      }
+    }
+  }
+  return false;
+}
+/*-------------------------------------------------------------------------*/

blake/blake_lang.h

+/*
+  Internal interface to Blake's language controls
+
+  (C) 2002 Daybo Logic, all rights reserved.
+  Don't include this header in non-Blake code.
+*/
+
+#ifndef __INC_BLAKE_LANG_H
+#define __INC_BLAKE_LANG_H
+
+#ifndef BLAKE_SOURCE
+# error ("Sod off, this header ain't for you")
+#endif /*!BLAKE_SOURCE*/
+
+OVERCHAT_C_IN_CPP bool blake_LangInit(OVERCHAT_PROTOTYPE_VOID);
+OVERCHAT_C_IN_CPP void blake_LangCleanup(OVERCHAT_PROTOTYPE_VOID);
+OVERCHAT_C_IN_CPP bool blake_LangIsInited(OVERCHAT_PROTOTYPE_VOID);
+
+#endif /*!__INC_BLAKE_LANG_H*/

blake/blake_lib

Empty file added.

blake/blake_main.c

 #include "blake_pendingloop.h"
 #include "blakedb.h"
 #include "blake_logger.h"
+#include "blake_netbuffer.h"
+#include "blake_lang.h"
 #include "blake_main.h"
 #include "stopcodes.h" /* For Panics */
 /*-------------------------------------------------------------------------*/
   "The file cannot be opened for exclusive access", /*blakeExclusiveFileFailure*/
   "The SA handle is bad", /*blakeBadSAHandle*/
   "The database record is corrupt", /*blakeDbRecordCorrupt*/
-  "The file is truncated" /*blakeFileTruncated*/
+  "The file is truncated", /*blakeFileTruncated*/
+  "Cannot open archived file" /*blakeArchivedFileError*/
 };
 
 /* French translations of the error messages */
 static short int ForceFutileLinkage(void); /* Call to make sure all compilers must link with the raw2c stuff */
 static void NotUserCleanup(void); /* For us only */
 /*-------------------------------------------------------------------------*/
-BLAKEAPI(bool) blake_Init(void)
+BLAKEAPI(blake_bool_t) blake_Init(void)
 {
   if ( !_inited ) {
     bool ok;
           ok = blakedb_InternalInit();
           if ( ok ) {
             ok = blake_logger_Init();
+            if ( ok ) {
+              ok = netbuffer_Init();
+              if ( ok ) {
+                ok = blake_LangInit();
+                if ( ok ) {
+                  ok = blake_BenchInit();
+                }
+              }
+            }
           }
         }
       }
   return _inited;
 }
 /*-------------------------------------------------------------------------*/
-BLAKEAPI(bool) blake_Cleanup(void)
+BLAKEAPI(blake_bool_t) blake_Cleanup(void)
 {
   if ( _inited ) {
     NotUserCleanup();
   short int crap = (short int)__rawimage_btfuck[0];
   crap += (short int)__rawimage_murder_microsoft[0];
   crap += (short int)__rawimage_sbeast[0];
+  crap += (short int)__rawimage_coup[0];
   return crap;
 }
 /*-------------------------------------------------------------------------*/
 static void NotUserCleanup()
 {
+  if ( blake_BenchIsInited() )
+    blake_BenchCleanup();
+
+  if ( blake_LangIsInited() )
+    blake_LangCleanup();
+
+  if ( netbuffer_IsInited() )
+    netbuffer_Cleanup();