Index: Daodan/MSVC/Flatline.c
===================================================================
--- Daodan/MSVC/Flatline.c	(revision 586)
+++ Daodan/MSVC/Flatline.c	(revision 587)
@@ -592,5 +592,4 @@
 bool FlatlineInitialize()
 {
-	
 	memset( Players, 0, sizeof( player_info ) * MAX_PLAYERS );
 	memset( PlayerList, 0, 4 * MAX_PLAYERS );
Index: Daodan/MSVC/Flatline.h
===================================================================
--- Daodan/MSVC/Flatline.h	(revision 586)
+++ Daodan/MSVC/Flatline.h	(revision 587)
@@ -38,27 +38,9 @@
 #include "Flatline_Packet.h"
 
-#define pad1_size (sizeof(int64_t) - sizeof(short))
-#define pad2_size (128 - (sizeof(short) + pad1_size + sizeof(int64_t)))
-
-#define breakpoint asm("int3")
-
-typedef struct {
-	short ss_family;
-	char pad1[pad1_size];
-	uint64_t pad64;
-	char pad2[pad2_size];
-} sockaddr_storage;
-
-typedef struct sockaddr sockaddr;
-typedef struct sockaddr_in sockaddr_in;
-typedef sockaddr_storage sockaddr_in6;
-
-bool NetUDPServer_Listen(uint16_t port, bool (*packet_callback)(char* data, int datalen, int from));
-bool NetUDPServer_Send(sockaddr* address, char* data, int datalen);
-
-int NetUDPSocket_Create(uint16_t port);
-int NetUDPSocket_Send(int socket, const sockaddr* address, const char* data, int datalen);
-void NetUDPSocket_Close(int sock);
-bool NetUDPSocket_Recieve(int socket, sockaddr_storage* address, char* data, uint16_t* datalen);
+
+//#define breakpoint asm("int3")
+
+
+#include "Flatline_Net.h"
 
 DWORD WINAPI StartServer(void* lol);
@@ -167,6 +149,8 @@
 typedef struct {
 	//int	FLATLINE;
-	int		id;
-	int		packet_index;
+	short	signature;
+	short	id;
+	int		size;
+	//int		packet_index;
 	union	
 	{
Index: Daodan/MSVC/Flatline_BSL.c
===================================================================
--- Daodan/MSVC/Flatline_BSL.c	(revision 586)
+++ Daodan/MSVC/Flatline_BSL.c	(revision 587)
@@ -7,4 +7,5 @@
 #include "Flatline.h"
 #include "Flatline_Server.h"
+#include "Mariusnet_Public.h"
 bool server_started = 0;
 bool client_connected = 0;
@@ -75,5 +76,6 @@
 	if(	NetPlatform_Initalize()) {
 		static flatline_packet packet;
-		sock = NetUDPSocket_Create(27777);
+		memset(&client_address, 0, sizeof(sockaddr_in));
+		sock = NetUDPSocket_Create(27777, &client_address);
 		address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr(args[0].value_str32 );	
 		//address.sin_family = AF_INET; address.sin_port = htons(27777); address.sin_addr.S_un.S_addr = inet_addr("192.168.0.1");	
@@ -225,4 +227,11 @@
 	return 0;
 }
+
+uint16_t ONICALL mnet_login(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
+{
+	MSNet_Login(args[0].value_str32, args[1].value_str32);
+	return 0;
+}
+
 void SLrFlatline_Initialize() 
 {
@@ -242,3 +251,5 @@
 	SLrScript_Command_Register_Void("con", "Activates a console", "con:int", con);
 	SLrScript_Command_Register_Void("ping", "pong!", "", ping);
-}
+
+	SLrScript_Command_Register_Void("login", "logs into mariusnet", "username:string password:string", mnet_login);
+}
Index: Daodan/MSVC/Flatline_Net.c
===================================================================
--- Daodan/MSVC/Flatline_Net.c	(revision 586)
+++ Daodan/MSVC/Flatline_Net.c	(revision 587)
@@ -65,8 +65,8 @@
 sockaddr_in client_address;
 
-int NetUDPSocket_Create(uint16_t port)
+int NetUDPSocket_Create(uint16_t port, sockaddr_in* address)
 {
 	int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
-	sockaddr_in address;	
+
 		unsigned long nonBlocking = 1;
 	if (sock < 0)
@@ -77,10 +77,10 @@
 	
 
-	memset(&client_address, 0, sizeof(sockaddr_in));
-	address.sin_family = AF_INET;
-	address.sin_addr.s_addr = htonl(INADDR_ANY);
-	address.sin_port =  htons(port);
-	
-	if (bind(sock, (sockaddr*)&address, sizeof(sockaddr_in)) < 0)
+//	memset(&client_address, 0, sizeof(sockaddr_in));
+	address->sin_family = AF_INET;
+	address->sin_addr.s_addr = htonl(INADDR_ANY);
+	address->sin_port =  htons(port);
+	
+	if (bind(sock, (sockaddr*)address, sizeof(sockaddr_in)) < 0)
 	{
 		DDrConsole_PrintF("could not bind port %d", port);
@@ -95,14 +95,12 @@
 	}
 	client_sock = sock;
-	client_address = address;
 	return sock;
 }
 
-int NetTCPSocket_Create(uint16_t port)
+int NetTCPSocket_Create(uint16_t port, sockaddr_in* address)
 {
 	int sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
-	sockaddr_in address;
-		unsigned long nonBlocking = 1;
-
+
+		unsigned long nonBlocking = 0;
 	if (sock < 0)
 	{
@@ -112,10 +110,10 @@
 	
 
-	memset(&client_address, 0, sizeof(sockaddr_in));
-	address.sin_family = AF_INET;
-	address.sin_addr.s_addr = htonl(INADDR_ANY);
-	address.sin_port =  htons(port);
-	
-	if (bind(sock, (sockaddr*)&address, sizeof(sockaddr_in)) < 0)
+//	memset(&client_address, 0, sizeof(sockaddr_in));
+	//address->sin_family = AF_INET;
+	//address->sin_addr.s_addr = INADDR_ANY;
+	//address->sin_port =  htons(port);
+	/*
+	if (bind(sock, (sockaddr*)address, sizeof(sockaddr_in)) < 0)
 	{
 		DDrConsole_PrintF("could not bind port %d", port);
@@ -123,15 +121,13 @@
 	}
 	
-
+	/*
 	if (ioctlsocket(sock, FIONBIO, &nonBlocking))
 	{
 		DDrConsole_PrintF("failed to set non-blocking socket");
 		return false;
-	}
-	client_sock = sock;
-	client_address = address;
+	}*/
+	//client_sock = sock;
 	return sock;
 }
-
 
 void NetUDPSocket_Close(int socket)
@@ -144,5 +140,6 @@
 	//currently only protects against duplicate packets.
 	int addr_size;
-#ifdef TRACK_PACKETS
+	int sent_bytes;
+#if 0 //#ifdef TRACK_PACKETS
 	static uint32_t packet_index = 0;
 	packet_index = (packet_index + 1);
@@ -161,5 +158,11 @@
 			addr_size = sizeof(sockaddr_storage);
 	}
-	return sendto(socket, data, datalen, 0, address, addr_size);
+	sent_bytes = sendto(socket, data, datalen, 0, address, addr_size);
+
+	if(sent_bytes == SOCKET_ERROR) {
+		NetCatchError();
+	}
+
+	return sent_bytes;
 }
 
@@ -182,30 +185,9 @@
 			return false;
 		}
-	}	
-	/*
-#ifdef TRACK_PACKETS
-	if(client_connected && !server_started) {
-		uint32_t index_mkr = ((flatline_packet*)(data))->packet_index;
-		//fancy way of checking if index_mkr is on one side of the max size of an int and last_packet is on the other
-		if( ((index_mkr - last_packet < 0x80000000) && (index_mkr > last_packet))
-		//if it is, subtract half the size of an int from each. ^_^
-			|| ((index_mkr - 0x80000000) > (last_packet - 0x80000000) ) )
-		{
-			return false;
-		}
-		else {
-			last_packet = index_mkr;
-		}
-	}
-	
-#endif
-	*/
-
+	}
 	*datalen = msg_size;				
 	return true;
 	
 }
-
-
 
 DWORD WINAPI StartServer(void* lol){
Index: Daodan/MSVC/Flatline_Win32.c
===================================================================
--- Daodan/MSVC/Flatline_Win32.c	(revision 586)
+++ Daodan/MSVC/Flatline_Win32.c	(revision 587)
@@ -1,14 +1,16 @@
 #include "Flatline.h"
-
+bool WSAStarted = 0;
 bool NetPlatform_Initalize()
 {
 	WSADATA wsaData;
-	
-	if (WSAStartup(MAKEWORD(2, 2), &wsaData))
+	if(!WSAStarted)
 	{
-		DDrConsole_PrintF("WSA initalization failed");
-		return false;
+		if (WSAStartup(MAKEWORD(2, 2), &wsaData))
+		{
+			DDrConsole_PrintF("WSA initalization failed");
+			return false;
+		}
+		DDrConsole_PrintF("net started using WSA version %d.%d", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
 	}
-	DDrConsole_PrintF("net started using WSA version %d.%d", LOBYTE(wsaData.wVersion), HIBYTE(wsaData.wVersion));
 	return true;
 }
Index: Daodan/MSVC/Mariusnet.c
===================================================================
--- Daodan/MSVC/Mariusnet.c	(revision 587)
+++ Daodan/MSVC/Mariusnet.c	(revision 587)
@@ -0,0 +1,548 @@
+
+#include <winsock2.h>
+#include "bool.h"
+#include "Flatline_Net.h"
+#include "Flatline_Win32.h"
+#include "Mariusnet_Defs.h"
+#include "Daodan_Console.h"
+#include <stdio.h>
+#include <inaddr.h>
+#pragma comment(lib, "wininet.lib")
+
+
+typedef struct hostent hostent ;
+typedef struct in_addr in_addr;
+
+char MariusLogin[32]={0};
+unsigned char MariusPassword[16]={0};
+
+m_room RoomList[64] = {0};
+bool RoomListGotten = 0;
+
+bool Are_We_Logged_In = 0;
+
+RGBA blue =		{0xFF, 0, 0, 0};
+RGBA green =	{0, 0xFF, 0, 0};
+RGBA red =		{0, 0, 0xFF, 0};
+
+RGBA grey = {0x80,0x80,0x80,0x80};
+
+int MariusNet_OutgoingPacketWrapper(int socket, const sockaddr* address, marius_packet* data, short datalen)
+{
+	data->header.PacketSize = htonl(datalen);
+	//NetUDPSocket_Send( socket, address, (char*)data, sizeof(marius_header) );
+	//datalen -= sizeof(marius_header);
+	//(char*)data += sizeof(marius_header);
+	return NetUDPSocket_Send( socket, address, (char*)data, datalen);
+}
+
+int PacketCached = 0;
+int MariusNet_IncomingPacketWrapper(int socket, char buffer[], int bufferlength, int flags)
+{
+	int inSize = 0;
+	unsigned fullSize = -1;
+	static char cacheBuffer[1440] = {0};
+	bool NeedMoreData = 0;
+	if(PacketCached)
+	{
+		unsigned int PacketSize = ntohl(((marius_packet*)cacheBuffer)->header.PacketSize);
+	/*
+		if(ntohs(((marius_packet*)cacheBuffer)->header.PacketSignature) != 0xDEAD)
+		{
+			PacketCached = PacketSize = 0;
+			NeedMoreData = 1;
+		}
+		*/
+
+		
+		
+		if(PacketCached >= PacketSize)
+		{
+			memcpy( buffer, cacheBuffer, PacketSize );
+			PacketCached -= PacketSize;
+		}
+		else
+		{
+			memcpy( buffer, cacheBuffer, PacketCached );
+			inSize += PacketCached;
+			NeedMoreData = 1;
+			PacketCached = 0;
+		}
+		if(PacketCached < 0)
+		{
+			DDrConsole_PrintF("Warning, took too much from cache");
+			PacketCached = 0;
+		}
+		else if (PacketCached > 0)// && ntohs((short*)(cacheBuffer + PacketSize)) == 0xDEAD)
+		{
+			memcpy( cacheBuffer, cacheBuffer + PacketSize, PacketCached );
+		}
+		else
+		{
+			memset(cacheBuffer, 0, 1440);
+		}
+		
+		if(!NeedMoreData) return PacketSize;
+
+	}
+	do
+	{
+		int tempSize = recv(socket, buffer + inSize, bufferlength, flags);
+		if(tempSize == SOCKET_ERROR)
+		{
+			NetCatchError();
+			return SOCKET_ERROR;
+		}
+		
+		if(fullSize == -1)
+		{
+			if(ntohs(((marius_packet*)buffer)->header.PacketSignature) != 0xDEAD)
+			{
+				DDrConsole_PrintF("Bad header signature...closing Mariusnet connection");
+				return SOCKET_ERROR;
+			}
+			fullSize = ntohl(((marius_packet*)buffer)->header.PacketSize);
+		}
+		inSize += tempSize;
+		
+	}
+	while(inSize < fullSize);
+	
+	//double packet madness
+	if(inSize > fullSize 
+		&& ntohs(*(short*)(buffer + fullSize)) == 0xDEAD 
+		&& ntohl(((marius_packet*)(buffer + fullSize))->header.PacketSize) > 0
+		&& inSize - fullSize > sizeof(marius_header)
+		)
+	{
+		memcpy(cacheBuffer, buffer + fullSize, inSize - fullSize);
+		
+		PacketCached = inSize - fullSize;
+	}
+	else PacketCached = 0;
+	return inSize;
+}
+
+
+sockaddr_in Marius_Server;
+
+
+bool MariusNet_Initialize()
+{
+	hostent* host_info = 0;
+	//host_info = gethostbyname("myth.mariusnet.com");
+	
+	host_info = gethostbyname("metaserver.lhowon.org");
+	if(!host_info)
+	{
+		DDrConsole_PrintF("Error, could not resolve myth.mariusnet.com");
+		return 1;
+	}
+	Marius_Server.sin_port = htons(6321);
+	Marius_Server.sin_family = AF_INET;
+	Marius_Server.sin_addr.S_un.S_addr = *(ULONG*)host_info->h_addr_list[0];
+	return 0;
+}
+
+void Initialize_MPacket( marius_packet* packet, short ID )
+{
+	memset( packet, 0, sizeof(marius_packet) );
+	packet->header.PacketSignature = htons(0xDEAD);
+	packet->header.PacketId = htons(ID);
+	
+}
+
+void Initialize_LoginPacket( marius_packet* packet)
+{
+	int NameSize = 0;
+	int TeamSize = 0;
+	char (*test)[] = packet;
+	Initialize_MPacket(packet, pt_PlayerLogin);
+	
+	packet->login.UpdateAppearance = 1;
+	packet->login.Platform = htons(1);
+	strncpy(packet->login.LoginId, MariusLogin, 32);
+	packet->login.EncryptionType = htons(1);
+	strcpy(packet->login.AppName, "MARATHON" ); //ONI ;)
+	strncpy(packet->login.BuildDate, __DATE__, 32 );
+	strncpy(packet->login.BuildTime, __TIME__, 32 );
+
+	
+	packet->login.PlayerInfo.clientVersion = htons(5000);
+	NameSize = sprintf(packet->login.PlayerInfo.Name, MariusLogin);
+	//TeamSize = sprintf(packet->login.PlayerInfo.Name + NameSize, "TCTF") + 1;
+	
+	packet->login.PlayerInfoSize = htons(40 + NameSize + TeamSize);
+}
+
+char EncryptionTypes[][32] = 
+{
+	"Plaintext",
+	"Braindead Simple",
+};
+
+enum {
+	SyntaxError,
+	GamesNotAllowed,
+	InvalidVersion,
+	BadUserOrPassword,
+	UserNotLoggedIn,
+	BadMetaserverVersion,
+	UserAlreadyLoggedIn,
+	UnknownGameType,
+	LoginSuccessful,
+	LogoutSuccessful,
+	PlayerNotInRoom,
+	GameAlreadyExists,
+	AccountAlreadyLoggedIn,
+	RoomFull,
+	AccountLocked,
+	NotSupported
+};
+
+static const char* sRoomNames[] = {
+	"Crows Bridge",
+	"Otter Ferry",
+	"White Falls",
+	"Silvermines",
+	"Shoal",
+	"Madrigal",
+	"Tyr",
+	"Ash",
+	"Scales",
+	"Covenant",
+	"Muirthemne",
+	"Seven Gates",
+	"Bagrada",
+	"The Barrier",
+	"Forest Heart",
+	"The Ermine",
+	"The Dire Marsh",
+	"The Highlands",
+	"The Drowned Kingdom",
+	"The Great Devoid",
+	"Shiver",
+	"The Caterthuns",
+	"Soulblighter",
+	"Balor",
+	"Sons of Myrgard",
+	"Heart of the Stone",
+	"Arrival",
+	"Ingue Ferroque",
+	"Vimy Ridge",
+	"Stilwell Road"
+};
+void MSNet_LoginError_Output( int code )
+{
+	switch(code)
+	{
+	case(BadUserOrPassword):
+		DDrConsole_PrintF( "Login denied: bad username or password." );
+		break;
+	case(UserAlreadyLoggedIn):
+		DDrConsole_PrintF( "Login denied: that user is already logged in.");
+		break;
+	case(AccountAlreadyLoggedIn):
+		DDrConsole_PrintF( "Login denied: that account is already logged in.");
+		break;
+	case(RoomFull):
+		DDrConsole_PrintF( "Login denied: room is full!?");
+		break;
+	case(AccountLocked):
+		DDrConsole_PrintF( "Login denied: your account is locked.");
+		break;
+	default:
+		DDrConsole_PrintF("There was a problem connecting to the server"
+			"that tracks Internet games. Please try again later.");
+		break;
+	}
+
+}
+int MSNet_Room_Join( short Room, char* Key)
+{
+	marius_packet mPacket = {0};
+
+	char incomingData[1400] = {0};
+	marius_packet* incomingPacket = (marius_packet*)incomingData;
+	int sent_bytes = 0;	
+
+	sockaddr_in SockAddr;
+	int Room_Socket = NetTCPSocket_Create(RoomList[Room].Port, &SockAddr);
+
+	sockaddr_in RoomAddr = {0};
+	RoomAddr.sin_port = RoomList[Room].Port;
+	RoomAddr.sin_family = AF_INET;
+	RoomAddr.sin_addr.S_un.S_addr = RoomList[Room].IPAddress;
+	
+
+
+	DDrConsole_PrintF("Joining room %hi", Room);
+
+	if(Room_Socket == -1)
+	{
+		DDrConsole_PrintF("Failed to initialize room socket!");
+	}
+	
+	if(connect( Room_Socket, (sockaddr *)&RoomAddr, sizeof(sockaddr_in)))
+	{
+		NetCatchError();
+		return 1;
+	}
+	
+	Initialize_MPacket(&mPacket, pt_ChatRoomLogin);
+	memcpy(mPacket.chatroom_join.RoomKey, Key, 32);
+	strcpy(mPacket.chatroom_join.Name, MariusLogin);
+	sent_bytes = MariusNet_OutgoingPacketWrapper(Room_Socket, (sockaddr*)&RoomAddr, (char*)&mPacket, 
+		sizeof(marius_header) + 33 + strlen(MariusLogin));
+	
+	
+
+	Initialize_MPacket(&mPacket, pt_RoomPlayerInfo);
+	mPacket.player_info.clientVersion = htons(5000);
+	sprintf(mPacket.player_info.Name, MariusLogin);
+	sent_bytes = MariusNet_OutgoingPacketWrapper(Room_Socket, (sockaddr*)&RoomAddr, (char*)&mPacket, 
+		sizeof(marius_header) + 40 + strlen(MariusLogin));
+
+	if(MariusNet_IncomingPacketWrapper(Room_Socket, incomingData, 1400, 0) == SOCKET_ERROR)
+	{
+		return 0;
+	}
+
+	if(ntohs(incomingPacket->header.PacketId)== pt_LoginInfo)
+	{
+		//DDrConsole_PrintF("Login failed: %s", incomingPacket->login_denied.DenialMessage );
+		MSNet_LoginError_Output(ntohl(incomingPacket->login_denied.code));
+		return 0;
+	}
+
+	while(1)
+	{
+		if(MariusNet_IncomingPacketWrapper(Room_Socket, incomingData, 1400, 0) == SOCKET_ERROR)
+		{
+			return 0;
+		}
+		switch(ntohs(incomingPacket->header.PacketId))
+		{
+		case pt_RoomList:
+		case pt_PlayerInfo:
+		case pt_GameList:
+		case pt_PlayerList:
+			//Do nothing for now
+			break;
+		case pt_BlueBarMsg:
+			DDrConsole_PrintColored(incomingPacket->motd.Message, 0, blue, grey );
+			break;
+		case pt_ChatMessage:
+			break;
+		case pt_KeepAlive:
+			MariusNet_OutgoingPacketWrapper(Room_Socket, (sockaddr*)&RoomAddr, incomingData, 
+				sizeof(marius_header));
+			break;
+		default:
+			DDrConsole_PrintF("Got packet of type %hi", ntohs(incomingPacket->header.PacketId));
+			break;
+		}
+	}
+	
+	return 0;
+}
+
+DWORD WINAPI MSNet_Handler(void* unused)
+{
+	int Port = 4156;
+	int Marius_Socket = -1;
+	int PlayerID;
+	char RoomToken[33] = {0};
+	int i = 0;
+
+	
+	
+	sockaddr_in Marius_Addr = {0};
+	
+	if(Are_We_Logged_In) 
+	{
+		DDrConsole_PrintF("You're already logged in!");
+		return 0;
+	}
+
+	NetPlatform_Initalize();
+
+
+	if(MariusNet_Initialize())
+	{
+		return 0;
+	}
+
+	//Horribly set up.
+	while( (Marius_Socket == -1 || Marius_Socket == 0 )&& Port < 6641)
+	{
+	
+		//Marius_Socket = NetTCPSocket_Create(Port, &Marius_Addr);
+		//NetUDPSocket_Close( Marius_Socket );
+		Marius_Socket = NetTCPSocket_Create(Port, &Marius_Addr);
+		//Port++;
+	}
+	
+	if(Marius_Socket != -1)
+	{
+		unsigned char incomingData[1400] = {0};
+		short incomingLength = 0;
+		marius_packet* incomingPacket = &incomingData;
+		//Initialize 
+		marius_packet mPacket;
+		int sent_bytes;
+		Initialize_LoginPacket(&mPacket);
+		
+		DDrConsole_PrintF("Logging into Mariusnet <%s>...",  inet_ntoa(Marius_Server.sin_addr));
+		if(connect( Marius_Socket, &Marius_Server, sizeof(sockaddr_in)))
+		{
+			NetCatchError();
+			return 0;
+		}
+		DDrConsole_PrintF("Sending Player Info...");
+		sent_bytes = MariusNet_OutgoingPacketWrapper(Marius_Socket, (sockaddr*)&Marius_Server, (char*)&mPacket, 
+			sizeof(marius_header) + sizeof(m_player_login) - (sizeof(m_player_info) - ntohs(mPacket.login.PlayerInfoSize) ) );
+		/*
+		if(!NetUDPSocket_Recieve(Marius_Socket, (sockaddr*)&Marius_Addr,incomingData, &incomingLength))
+		{
+			DDrConsole_PrintF("Data: %s Length %i", incomingData, incomingLength);
+			return 0;
+		}
+		*/
+		if(MariusNet_IncomingPacketWrapper(Marius_Socket, incomingData, 1400, 0) == SOCKET_ERROR)
+		{
+			return 0;
+		}
+		
+		if(ntohs(incomingPacket->header.PacketId)== pt_EncryptionKey)
+		{
+			//recv( Marius_Socket, incomingData, 1440, 0);
+			DDrConsole_PrintF("Encryption Type %s", EncryptionTypes[ntohs(incomingPacket->salt.EncryptionType)] );
+
+			Initialize_MPacket(&mPacket, pt_Password);
+			if(incomingPacket->salt.EncryptionType)
+			{
+				
+				unsigned char* Hash = mPacket.password.passHash;
+				unsigned char* Salt = incomingPacket->salt.salt;
+				unsigned char Pass[16] = {0};
+
+				memset(Pass, 0x23, 16);
+				strcpy(Pass, MariusPassword );
+
+				for( i = 0; i < 16; i++ ) Hash[i] = Pass[i]^Salt[i];
+				for( i = 1; i < 16; i++ ) Hash[i] = Hash[i]^Hash[i-1];
+				for( i = 1; i < 16; i++ ) 
+				{
+					short value = ~( Hash[i]*Hash[i-1] );
+					Hash[i] = (unsigned char) value;
+
+				}
+			}
+			else
+			{
+				strncpy(mPacket.password.passHash, MariusPassword, 16);
+			}
+
+			DDrConsole_PrintF("Sending Password...");
+			sent_bytes = MariusNet_OutgoingPacketWrapper(Marius_Socket, (sockaddr*)&Marius_Server, (char*)&mPacket, sizeof(marius_header) + sizeof(m_password) );
+
+			if(!NetUDPSocket_Recieve(Marius_Socket, (sockaddr*)&Marius_Addr,incomingData, &incomingLength))
+			{
+				return 0;
+			}
+			DDrConsole_PrintF("Password ACK!");
+			if(ntohs(incomingPacket->header.PacketId)== pt_PasswordAck)
+			{
+
+				Initialize_MPacket(&mPacket, pt_Localization);
+				mPacket.localization.one = htonl(1);
+				mPacket.localization.two = htonl(2);
+				mPacket.localization.three = htonl(3);
+				mPacket.localization.zero = 0;
+				sent_bytes = MariusNet_OutgoingPacketWrapper(Marius_Socket, (sockaddr*)&Marius_Server, (char*)&mPacket, sizeof(marius_header) + sizeof(m_localization) );
+
+				if(MariusNet_IncomingPacketWrapper(Marius_Socket, incomingData, 1400, 0) == SOCKET_ERROR)
+				{	
+					return 0;
+				}
+			}
+		}
+
+		if(ntohs(incomingPacket->header.PacketId)== pt_UserLoggedIn)
+		{
+			PlayerID = ntohl(incomingPacket->login_success.userID);
+			//Not sure if this is a string or byte array, so I allocated 33 bytes,
+			//so it always zero terminates.
+			memcpy(RoomToken, incomingPacket->login_success.Token, 32);
+			DDrConsole_PrintF("Logged into Mariusnet!");
+		}
+		else if(ntohs(incomingPacket->header.PacketId)== pt_LoginInfo)
+		{
+			//DDrConsole_PrintF("Login failed: %s", incomingPacket->login_denied.DenialMessage );
+			MSNet_LoginError_Output(ntohl(incomingPacket->login_denied.code));
+			return 0;
+		}
+		else 
+		{
+			DDrConsole_PrintF("Something went wrong! Disconnecting from Mariusnet");
+			return 0;
+		}
+
+
+		do
+		{
+			if(MariusNet_IncomingPacketWrapper(Marius_Socket, incomingData, 1400, 0) == SOCKET_ERROR)
+			{	
+				return 0;
+			}
+			if(ntohs(incomingPacket->header.PacketId)== pt_RoomList)
+			{
+				DDrConsole_PrintF("Got room list!");
+				RoomListGotten = 1;
+				memcpy(RoomList, incomingPacket->roomlist.Rooms, 
+					ntohl(incomingPacket->header.PacketSize) - sizeof(marius_header));
+			}
+			else if(ntohs(incomingPacket->header.PacketId)== pt_PlayerInfo)
+			{
+				//What do we do with this?!
+				DDrConsole_PrintF("Got player info!");
+			}
+			else
+			{
+				DDrConsole_PrintF("Invalid packet type %hi", ntohs(incomingPacket->header.PacketId));
+				return 0;
+			}
+		}
+		while(PacketCached || !RoomListGotten);
+
+		for(i = 0; i < 64, RoomList[i].IPAddress != 0 ; i++)
+		{
+			int IP = ntohl(RoomList[i].IPAddress);
+			DDrConsole_PrintF("Room %i %s IP %s Port %hi Players %hi", 
+				i, 
+				sRoomNames[ntohs(RoomList[i].RoomIndex)],
+				inet_ntoa(*(in_addr*)&IP),
+				ntohs(RoomList[i].Port),
+				ntohs(RoomList[i].PlayerCount)				
+				);
+			}
+		
+		closesocket(Marius_Socket);
+
+		MSNet_Room_Join( 1, RoomToken );
+
+		
+	}
+	return 0;
+}
+
+bool MSNet_Login(char* username, char* password)
+{
+	sprintf_s(MariusLogin, 32, "%s", username);
+	sprintf_s(MariusPassword, 16, "%s", password);
+	CreateThread(NULL, 0, MSNet_Handler, NULL, 0, 0);
+
+	return 0;
+}
+
Index: Daodan/MSVC/Mariusnet_Defs.h
===================================================================
--- Daodan/MSVC/Mariusnet_Defs.h	(revision 587)
+++ Daodan/MSVC/Mariusnet_Defs.h	(revision 587)
@@ -0,0 +1,193 @@
+//to client
+enum
+{
+pt_RoomList = 0x0000,
+pt_PlayerList = 0x0001,
+pt_GameList = 0x0002,
+pt_UserLoggedIn = 0x7,//0x0003,
+pt_EncryptionKey = 0x0006,
+pt_LoginInfo = 0x3,//0x0007,
+pt_PlayerInfo = 0x0008,
+pt_PlayerId = 0x0009,
+pt_BlueBarMsg = 0x000A,
+pt_PasswordAck = 0x000C,
+pt_FindResponse = 0x000E,
+pt_BuddyList = 0x000F, // the actual buddy list - i.e. names and such
+pt_OrderList = 0x0010,
+pt_PlayerInfoResponse = 0x0011,
+pt_UpdatePlayerStats = 0x0012,
+pt_UpdateBuddyList = 0x0013, // buddy status - i.e. online/offline
+pt_UpdateOrderList = 0x0014,
+};
+
+//from client
+enum
+{
+pt_PlayerLogin = 0x0064,
+pt_ChatRoomLogin = 0x0065,
+pt_RoomPlayerInfo = 0x0067,
+pt_GameInfo = 0x0068,
+pt_RemoveGame = 0x0069,
+pt_SetPlayerState = 0x006B,
+pt_Password = 0x006D,
+pt_RequestRefresh = 0x006E,
+pt_GamePlayerList = 0x006F, // game start player list
+pt_PlayerScores = 0x0070, // game over player scores
+pt_ResetScoring = 0x0071, // reset metaserver game scoring
+pt_StartGame = 0x0072,
+pt_Localization = 0x0073,
+pt_GameSearchQuery = 0x0074,
+pt_FindPlayer = 0x0075,
+pt_BuddyListQuery = 0x0076, // request a buddy list update
+pt_OrderListQuery = 0x0077,
+pt_UpdateBuddy = 0x0078, // add/remove buddy
+pt_PlayerInfoQuery = 0x0079,
+pt_SetPlayerStats = 0x007A, // change player stats (city/state/profile)
+pt_ChatMessage = 0x00C8,
+pt_WhisperMessage = 0x00C9,
+pt_KeepAlive = 0x00CA,
+pt_SessionKey = 0x00CB,
+};
+
+enum
+{
+ctMyth1 = 0,
+ctMyth2 = 1,
+// ctMyth3 = 2;
+ctMarathon = 3,
+ctMyth1Unified = 4,
+ctMyth2Unified = 5,
+ctMyth3Unified = 6,
+};
+
+
+typedef struct
+{
+	short PacketSignature;// = 0xDEAD;
+    short PacketId;
+    unsigned int PacketSize;
+} marius_header;
+
+typedef struct
+{
+	short Red;
+    short Green;
+    short Blue;
+    short Flags;
+} m_colour;
+
+typedef struct
+{
+	char Icon;
+	char pad;
+	short Flags; // 0=active, 1=inactive, in a game, grayed out, can't see chat
+	m_colour Colors[2];
+	short orderIndex;
+	short clientVersion;
+	char stupid_14byte_pad[14];
+	char Name[112];     // 2 #0 terminated fields - Name, Team Name
+} m_player_info;
+
+typedef struct
+{
+	short Platform; //Windows - 1
+	short MetaVersion; //0
+	char pad[3]; 
+    char UpdateAppearance;                      // save player settings on server,     change to bits, bit 0=update, bit 1=demo
+    int PlayerId; //0
+    short EncryptionType;  //0 - kCRYPT_PLAINTEXT, screw encryption for now
+    short PlayerInfoSize;  //40 + strlen(playername) + strlen(plaerteam(
+    char AppName[32];		//MARATHON...later ONI ;)
+    char BuildDate[32];		//_DATE_
+    char BuildTime[32];		//_TIME_
+    char LoginId[32];		//username
+    m_player_info PlayerInfo;       
+} m_player_login;
+
+typedef struct
+{
+	short EncryptionType;
+	unsigned char salt[16];
+} m_salt;
+
+typedef struct
+{
+	int one;
+	int two;
+	int three;
+	int zero;
+} m_localization;
+
+typedef struct
+{
+	unsigned char passHash[16];
+} m_password;
+
+typedef struct
+{
+	int userID;
+	short order;
+	short unused;
+	char Token[32];
+		
+} m_login_success;
+
+typedef struct
+{
+	int code;
+	char DenialMessage[];
+} m_login_denied;
+
+typedef struct
+{
+	short RoomIndex;
+	short PlayerCount;
+	int IPAddress;
+	short Port;
+	short GameCount;
+	int pad[3];
+} m_room;
+
+typedef struct
+{
+	m_room Rooms[64];
+} m_roomlist;
+
+typedef struct
+{
+	char RoomKey[32];
+	char Name[32];
+} m_chatroom_join;
+
+typedef struct
+{
+	char Message[512];
+} m_motd;
+
+typedef struct
+{
+
+    ColorStuff : TColorInfo;
+	int    SenderId;
+    int		TargetId;
+    char Message[256];
+}
+
+
+typedef struct
+{
+	marius_header header;
+	union
+	{
+		m_player_login login;
+		m_password password;
+		m_localization localization;
+		m_salt salt;
+		m_login_success login_success;
+		m_login_denied login_denied;
+		m_roomlist roomlist;
+		m_chatroom_join chatroom_join;
+		m_player_info player_info;
+		m_motd motd;
+	};
+} marius_packet;
Index: Daodan/MSVC/Mariusnet_Public.h
===================================================================
--- Daodan/MSVC/Mariusnet_Public.h	(revision 587)
+++ Daodan/MSVC/Mariusnet_Public.h	(revision 587)
@@ -0,0 +1,1 @@
+bool MSNet_Login(char* username, char* password);
