Index: Daodan/MSVC/Flatline.c
===================================================================
--- Daodan/MSVC/Flatline.c	(revision 582)
+++ Daodan/MSVC/Flatline.c	(revision 583)
@@ -47,4 +47,12 @@
 }
 
+enum
+{
+	JustSpawned,
+	FirstPass,
+	SecondPass,
+	NoPass,
+};
+
 bool FLrServer_PacketCallback(char* data, int datalen, int from)
 {
@@ -159,16 +167,16 @@
 	case CHANGE_NAME:
 		; //wtf, needed or i get an error.
-		DDrConsole_PrintF("Changing Name to: %s", packet->data);
+	//	DDrConsole_PrintF("Changing Name to: %s", packet->data);
 		for(i = 0; i < MAX_PLAYERS; i++) {
-			if(Players[i].ip == sender.sin_addr.S_un.S_addr) {
+			if(PlayerList[i] && PlayerList[i]->ip == sender.sin_addr.S_un.S_addr) {
 				found_player = 1;
 				break;
 			}	
 		}
-		if(found_player == 0) return true;
+		if(found_player == 0) break;
 		else {
 			bool name_exists = 0;
 			for(j = 0; j < MAX_PLAYERS; j++) {
-				if(!strcmp(packet->data, Players[j].name)) {
+				if(PlayerList[j] && !strcmp(packet->data, PlayerList[j]->name)) {
 					name_exists = 1;
 					break;
@@ -176,9 +184,5 @@
 			}
 			if(!name_exists) {
-				char message_buffer[1024];
-				sprintf(message_buffer,"%s changed their name to %s", Players[i].name, packet->data);
-				COrMessage_Print(message_buffer, "name_change", 0);
-				memcpy(Players[i].name, packet->data, 256);
-
+				FLsUpdateName( i, packet->data );
 			}
 			break;
@@ -193,5 +197,5 @@
 		}
 
-		if(found_player == 0) return true;
+		if(found_player == 0) break;
 		else {
 			input_struct * packet_input = &packet->input_struct;
@@ -217,5 +221,5 @@
 		}
 
-		if(found_player == 0) return true;
+		if(found_player == 0) break;
 		if(packet->ping != lastPingTime)
 		{
@@ -301,4 +305,15 @@
 			case MESSAGE:
 				COrMessage_Print(packet.data, "chat", 0);
+				break;
+			case CHANGE_NAME:
+				if(PlayerList[(char)packet.data[0]])
+				{
+					char message_buffer[1024];
+					sprintf(message_buffer,"%s changed their name to %s", PlayerList[(char)packet.data[0]]->name, packet.data + 1);
+					COrMessage_Print(message_buffer, "name_change", 0);
+
+					sprintf_s(PlayerList[packet.data[0]]->name, 32, "%s", packet.data + 1);
+
+				}
 				break;
 			case CONNECT_SEND:
@@ -331,4 +346,5 @@
 						Players[chr_index].spawnnumber = chr_index;
 						DDrConsole_PrintF("Spawning player %s, class %s, slot  %i", ((new_player*)(packet.data))->Character.OSD.Name, ((new_player*)(packet.data))->Character.OSD.Class,chr_index) ;
+						sprintf_s(Players[chr_index].name, 32, "%s", ((new_player*)(packet.data))->Character.OSD.Name);
 					}
 					//Players[((new_player*)(packet.data))->Playernumber].spawnnumber = ONrGameState_NewCharacter(&(((new_player*)(packet.data))->Character), NULL, NULL, 0);
@@ -347,5 +363,8 @@
 
 					memcpy( &(PlayerList[i]->player_data), pd, sizeof(player_data) );
-
+					if(PlayerList[i]->player_data.Health == 0)
+					{
+						short breakfast = 1;
+					}
 					if( !server_started && pd->rare_sync_index > PlayerList[i]->rare_sync_index )
 					{
@@ -358,5 +377,5 @@
 					}
 
-					PlayerList[i]->DataApplied = 0;
+					PlayerList[i]->DataApplied = NoPass;
 
 
@@ -419,4 +438,5 @@
 							PlayerList[Player]->DesiredFacing = packet.all_input[Player].DesiredFacing;
 							PlayerList[Player]->Position = packet.all_input[Player].Position;
+							PlayerList[Player]->NeedToSetFP = 1;
 						}
 					}
@@ -462,4 +482,6 @@
 
 					DDrConsole_PrintColored("Connection successful!",0,green, grey);
+
+					sprintf_s( PlayerList[client_slot]->name, 32, "%s", player_name );
 
 					//disable local input.
@@ -528,10 +550,5 @@
 } IMtPoint2D;
 static flatline_packet cache_input = {0};
-enum
-{
-	FirstPass,
-	SecondPass,
-	NoPass,
-};
+
 bool ShouldSendUpdate( int i, Character* Player, ActiveCharacter* Active_Player )
 {
@@ -545,8 +562,7 @@
 void * ONICALL FLrInput_Update_Keys(void) 
 {
-	uint16_t i;
+	uint32_t i;
 	flatline_packet all_input = {0};
 	int16_t InputIndex = 0;
-	//ActiveCharacter * Active_Player = ONgGameState->ActiveCharacters;
 	
 	if(client_connected) 
@@ -559,5 +575,4 @@
 		input_packet.id = PLAYER_INPUT;
 		input_packet.input_struct.Time = ONgGameState->GameTime;
-//		((GameState*)(ONgGameState))->Input.Current.Actions1 |= Action_Backward | Action_StepLeft;
 		input_packet.input_struct.Actions1 = ((GameState*)(ONgGameState))->Input.Current.Actions1;
 		input_packet.input_struct.Actions2 = ((GameState*)(ONgGameState))->Input.Current.Actions2;
@@ -593,6 +608,14 @@
 		GameInput * Active_Input;
 		if(PlayerList[i] == 0) continue;
+		
 		Player = PlayerList[i]->Chr;
-		if(server_started)
+		Active_Player = ONrGetActiveCharacter( PlayerList[i]->Chr);
+
+		if(!Player)
+		{
+			DDrConsole_Print("Warning, missing Character!");
+			continue;
+		}
+		if(server_started && PlayerList[i]->Chr->Health > 0 )
 		{
 
@@ -609,4 +632,9 @@
 			//Infinity...
 			*(int *)&all_input.all_input[InputIndex].Position.X = 0x7f800000;
+			if(Active_Player)
+			{
+				all_input.all_input[InputIndex].Position = Active_Player->PhyContext->Position;
+			}
+
 
 			all_input.all_input[InputIndex].PlayerNum = i;
@@ -614,8 +642,24 @@
 		}
 
-		if( Player->Health == 0) 
+		
+		//Set the health properly first.
+		if( client_connected && PlayerList[i]->DataApplied == FirstPass )
 		{
-			int Actions;
+			ONrCharacter_SetHitPoints(  PlayerList[i]->Chr, PlayerList[i]->player_data.Health);
+		}
+		//If the player is dead
+		if( PlayerList[i]->Chr->Health == 0 )
+			
+		{
 			const short TicksToRespawn = 3 * 60;
+			
+			//Permanently kill off dumb AI
+			if(PlayerList[i]->flags & PF_SCRIPTEDAI)
+			{
+				FLrPlayerDisconnect( i );
+				continue;
+			}
+
+			//Just to know if we have started counting off the respawn
 			if(PlayerList[i]->state != STATE_DEAD)
 			{
@@ -626,33 +670,46 @@
 					ONrGameState_Timer_Start( "", TicksToRespawn  );
 				}
-			}
-
-			if(server_started && i == 0)
+
+				if(server_started)
+				{
+					FLsPublic_Event( EV_KILLED, &i );	
+				}
+				
+			}
+
+			//Server respawning
+			if(server_started)
 			{
-				Actions =  ONgGameState->Input.Current.Actions1;
-			}
-			else
-			{
-				Actions = PlayerList[i]->Actions1;
-			}
-
-			if(PlayerList[i]->flags & PF_SCRIPTEDAI)
-			{
-				FLrPlayerDisconnect( i );
-			}
-			else if(ONgGameState->GameTime - PlayerList[i]->DeathTime < TicksToRespawn )
+				int Actions;
+				if(i == 0)
+				{
+					Actions =  ONgGameState->Input.Current.Actions1;
+				}
+				else
+				{
+					Actions = PlayerList[i]->Actions1;
+				}
+
+				if(ONgGameState->GameTime - PlayerList[i]->DeathTime > TicksToRespawn && 
+					(Actions & (Action_Punch | Action_Kick)) )
+				{
+					FLrPlayerRespawn( i );
+					
+					FLsPublic_Event( EV_RESPAWN, &i );
+				}
+				else
+				{
+					continue;
+				}
+			}
+			else //clients?!
 			{
 				continue;
 			}
-			else if(Actions & (Action_Punch | Action_Kick))
-			{
-				FLrPlayerRespawn( i );
-			}
-			continue;
-
-
-		}
-
-		Active_Player = ONrGetActiveCharacter( PlayerList[i]->Chr);
+		}
+
+		PlayerList[i]->state = STATE_ALIVE;
+
+		
 		
 		if(Active_Player == 0) continue;
@@ -662,8 +719,5 @@
 		//Active_Player->PlayingFilm.Flags = 1;
 		Active_Input = &(Active_Player->Input);
-		if(server_started)
-		{
-			all_input.all_input[InputIndex - 1].Position = Active_Player->PhyContext->Position;
-		}
+
 		if(server_started && 
 			ShouldSendUpdate( i, PlayerList[i]->Chr, Active_Player) )
@@ -728,32 +782,22 @@
 
 
-			if( !server_started && PlayerList[i]->player_data.Health != 0) {
+			if( !server_started && PlayerList[i]->player_data.Health != 0 && PlayerList[i]->Chr->Health != 0) {
 				void* OldAnimation;
 				void* Animation;
 				player_data* pd = &PlayerList[i]->player_data;
 				
-				PlayerList[i]->Chr->Facing = PlayerList[i]->Facing;					
-				PlayerList[i]->Chr->DesiredFacing = PlayerList[i]->DesiredFacing;
+				//This is getting crazy. WTB new packet system
+				if(PlayerList[i]->NeedToSetFP)
+				{
+					PlayerList[i]->Chr->Facing = PlayerList[i]->Facing;					
+					PlayerList[i]->Chr->DesiredFacing = PlayerList[i]->DesiredFacing;
 				
-				if(*(int*)&PlayerList[i]->Chr->Position.X != 0x7f800000)
-				{
-					Active_Player->PhyContext->Position = PlayerList[i]->Position;					
-				}
-				else
-				{
-					int breakfast = 0;
-				}
-				/*
-				if(isnan(Active_Player->PhyContext->Position.Y) || 
-					isnan(Active_Player->PhyContext->Position.X) || 
-					isnan(Active_Player->PhyContext->Position.Z) )
-				{
-					//DDrConsole_PrintF("Player is NAN! %x %x", Active_Player->PhyContext->Position.Y, PlayerList[i]->Height);
-					DDrConsole_PrintF("Player is NAN! %x %x %x", Active_Player->PhyContext->Position.X, Active_Player->PhyContext->Position.Y, Active_Player->PhyContext->Position.Z);
-					//DDrConsole_PrintF("Velocity %x %x %x", Active_Player->PhyContext->Velocity.X, Active_Player->PhyContext->Velocity.Y, Active_Player->PhyContext->Velocity.Z);
-					
-					
-				}
-				*/
+					if(*(int*)&PlayerList[i]->Chr->Position.X != 0x7f800000)
+					{
+						Active_Player->PhyContext->Position = Player->Location = PlayerList[i]->Position;					
+
+					}
+					PlayerList[i]->NeedToSetFP = 0;
+				}
 
 				if( PlayerList[i]->DataApplied == FirstPass )
@@ -761,5 +805,5 @@
 					PlayerList[i]->DataApplied = SecondPass;
 
-					Player->Health = PlayerList[i]->player_data.Health;
+					//Player->Health = PlayerList[i]->player_data.Health;
 					PlayerList[i]->Chr->MaxHealth = PlayerList[i]->player_data.MaxHealth;
 
@@ -844,38 +888,45 @@
 					if (PlayerList[i]->player_data.throw_data.throwName[0] != 0)
 					{
-						short throwTarget = PlayerList[pd->throw_data.throwing]->spawnnumber;
-						if ((throwTarget != Active_Player->throwing) &&
-							(pd->throw_data.throwFrame < 10))
+						if(PlayerList[pd->throw_data.throwing])
 						{
-							void	*throw_animation;
-							ActiveCharacter* Target;
-							// get the animation
-
-							TMrInstance_GetDataPtr(
-								'TRAM',
-								pd->throw_data.throwName,
-								&throw_animation);
-							//if (error) return;
-
-							// set the throw target
-							Active_Player->ThrowTargetCharacter = &ONgGameState->CharacterStorage[throwTarget];
-							Target = ONrGetActiveCharacter(Active_Player->ThrowTargetCharacter);
-							if ((Target->Animation != throw_animation) &&
-								(OldAnimation != Animation) &&
-								!(Active_Player->ThrowTargetCharacter->Flags & ONcCharacterFlag_BeingThrown))
+							short throwTarget = PlayerList[pd->throw_data.throwing]->spawnnumber;
+							if ((throwTarget != Active_Player->throwing) &&
+								(pd->throw_data.throwFrame < 10))
 							{
-								// set the throw variables
-								Active_Player->targetThrow	= throw_animation;
-								Active_Player->throwing		= throwTarget;
-
-								// run the throw
-								ONrCharacter_NewAnimationHook(Player, Active_Player);
-
-								if (Active_Player->ThrowTargetCharacter)
+								void	*throw_animation;
+								ActiveCharacter* Target;
+								// get the animation
+
+								TMrInstance_GetDataPtr(
+									'TRAM',
+									pd->throw_data.throwName,
+									&throw_animation);
+								//if (error) return;
+
+								// set the throw target
+								Active_Player->ThrowTargetCharacter = &ONgGameState->CharacterStorage[throwTarget];
+								Target = ONrGetActiveCharacter(Active_Player->ThrowTargetCharacter);
+								if ((Target->Animation != throw_animation) &&
+									(OldAnimation != Animation) &&
+									!(Active_Player->ThrowTargetCharacter->Flags & ONcCharacterFlag_BeingThrown))
 								{
-									Target->Frame += 2;
-									Target->thrownBy = Player->Number;
+									// set the throw variables
+									Active_Player->targetThrow	= throw_animation;
+									Active_Player->throwing		= throwTarget;
+
+									// run the throw
+									ONrCharacter_NewAnimationHook(Player, Active_Player);
+
+									if (Active_Player->ThrowTargetCharacter)
+									{
+										Target->Frame += 2;
+										Target->thrownBy = Player->Number;
+									}
 								}
 							}
+						}
+						else
+						{
+							DDrConsole_PrintF("Warning, tried to throw nonexistant player %hi", pd->throw_data.throwing );
 						}
 					} //throw check
@@ -885,5 +936,5 @@
 		
 		//Check for character switching requests
-		if(server_started && PlayerList[i]->Actions1 & Action_Block && PlayerList[i]->ShapeshiftCooldown < ONgGameState->GameTime)
+		if(server_started && PlayerList[i]->player_data.Health != 0 && PlayerList[i]->Chr->Health != 0 && PlayerList[i]->Actions1 & Action_Block && PlayerList[i]->ShapeshiftCooldown < ONgGameState->GameTime)
 		{
 			int error;
@@ -1002,5 +1053,5 @@
 					TSrContext_SetShade(ScoreboardInstance, green);
 				}
-				TSrContext_DrawText(ScoreboardInstance, PlayerList[i]->Chr->Name, 255, 0, &DrawLocation);
+				TSrContext_DrawText(ScoreboardInstance, PlayerList[i]->name, 255, 0, &DrawLocation);
 				TSrContext_SetShade(ScoreboardInstance, white);
 				DrawLocation.x += 150;
Index: Daodan/MSVC/Flatline.h
===================================================================
--- Daodan/MSVC/Flatline.h	(revision 582)
+++ Daodan/MSVC/Flatline.h	(revision 583)
@@ -164,6 +164,6 @@
 //used for storing data about each player
 typedef struct {
-	int	FLATLINE;
-	char	id;
+	//int	FLATLINE;
+	int		id;
 	int		packet_index;
 	union	
@@ -180,5 +180,5 @@
 		flatline_event	flatline_event;
 		uint32_t		ping;
-		player_input	all_input[32];
+		player_input	all_input[33];
 	};
 } flatline_packet;
@@ -213,4 +213,5 @@
 enum FlatlineEvent {
 	EV_RESPAWN,
+	EV_KILLED,
 	EV_DISCONNECT,
 	EV_DOOR_OPEN,
@@ -269,5 +270,5 @@
 	uint32_t Ping;
 	bool DataApplied;
-	
+	bool NeedToSetFP;
 	uint32_t ShapeshiftCooldown;
 } player_info;
Index: Daodan/MSVC/Flatline_BSL.c
===================================================================
--- Daodan/MSVC/Flatline_BSL.c	(revision 582)
+++ Daodan/MSVC/Flatline_BSL.c	(revision 583)
@@ -43,5 +43,5 @@
 	if(server_started)
 	{
-		sprintf_s(PlayerList[0]->Chr->Name,32, args[0].value_str32);
+		FLsUpdateName( 0, args[0].value_str32 );
 	}
 	return 0;
@@ -129,6 +129,10 @@
 uint16_t ONICALL kick(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
 {
+	if(server_started && PlayerList[args[0].value_int32])
+	{
+	ONrCharacter_SetHitPoints(PlayerList[args[0].value_int32]->Chr, 0);
 	FLrPlayerDisconnect(args[0].value_int32);
 	FLsPublic_Event(EV_DISCONNECT, &args[0].value_int32);
+	}
 	return 0;
 }
@@ -180,4 +184,5 @@
 			PlayerList[playerlist_slot]->spawnnumber = player_slot;
 			PlayerList[playerlist_slot]->Chr = &((Character *)(((GameState * )(ONgGameState))->CharacterStorage))[player_slot];
+			sprintf_s(PlayerList[playerlist_slot]->name, 32, "%s", PlayerList[playerlist_slot]->Chr->Name);
 			//			PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF
 			//			if(!is_bot) PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; //WTF
Index: Daodan/MSVC/Flatline_Server.c
===================================================================
--- Daodan/MSVC/Flatline_Server.c	(revision 582)
+++ Daodan/MSVC/Flatline_Server.c	(revision 583)
@@ -78,5 +78,6 @@
 			//PlayerList[playerlist_slot]->Chr->Flags = chr_dontaim | chr_unkillable; //&= 0xFFBFFFFF; //WTF
 			if(!is_bot) PlayerList[playerlist_slot]->Chr->Flags &= 0xFFBFFFFF; //WTF, magic number. 
-			sprintf(PlayerList[playerlist_slot]->Chr->Name, "%.31s", name);		
+			sprintf_s(PlayerList[playerlist_slot]->Chr->Name, 32, "%s", name);		
+			sprintf_s(PlayerList[playerlist_slot]->name, 32, "%s", name);		
 			UDPServer_SendToAll( (char*)&new_char, sizeof(new_player) + FLATLINE_HEADER );
 			
@@ -91,5 +92,5 @@
 		PlayerList[playerlist_slot]->ip = ip;
 		PlayerList[playerlist_slot]->list_slot = playerlist_slot;
-		sprintf(PlayerList[playerlist_slot]->name,"%.31s",name);
+		sprintf_s(PlayerList[playerlist_slot]->name, 32, "%s", name);		
 		
 		MultiplayerStatus.PleaseUpdateAllPlayers = 1;
@@ -152,2 +153,21 @@
 	UDPServer_SendToAll(&ping, FLATLINE_HEADER + 4);
 }
+
+void FLsUpdateName( int index, char* name )
+{
+	flatline_packet message;
+	int message_size;	
+
+	char message_buffer[1024];
+	sprintf(message_buffer,"%s changed their name to %s", PlayerList[index]->name, name);
+	COrMessage_Print(message_buffer, "name_change", 0);
+	
+	sprintf_s(PlayerList[index]->name, 32, "%s", name);
+	sprintf_s(PlayerList[index]->Chr->Name, 32, "%s", name);
+
+	message.id = CHANGE_NAME;
+	message.data[0] = index;
+	message_size = sprintf(message.data + 1, "%s", name);
+
+	UDPServer_SendToAll(&message, message_size + 2 + FLATLINE_HEADER);
+}
Index: Daodan/MSVC/Flatline_Server.h
===================================================================
--- Daodan/MSVC/Flatline_Server.h	(revision 582)
+++ Daodan/MSVC/Flatline_Server.h	(revision 583)
@@ -13,3 +13,4 @@
 void FLrServer_Initialize();
 void FLsPingAll();
+void FLsUpdateName( int index, char* name );
 #endif
