diff --git a/Generals/Code/GameEngine/Include/Common/Language.h b/Generals/Code/GameEngine/Include/Common/Language.h index a2db8eafaf..d03ed08d98 100644 --- a/Generals/Code/GameEngine/Include/Common/Language.h +++ b/Generals/Code/GameEngine/Include/Common/Language.h @@ -76,7 +76,6 @@ typedef enum } LanguageID; #define GameStrcpy wcscpy -#define GameStrncpy wcsncpy #define GameStrlen wcslen #define GameStrcat wcscat #define GameStrcmp wcscmp diff --git a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp index 0c02343939..2dcc472060 100644 --- a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp @@ -540,8 +540,7 @@ WindowMsgHandledType ScoreScreenSystem( GameWindow *window, UnsignedInt msg, req.arg.addbuddy.id = playerID; UnicodeString buddyAddstr; buddyAddstr = TheGameText->fetch("GUI:BuddyAddReq"); - wcsncpy(req.arg.addbuddy.text, buddyAddstr.str(), MAX_BUDDY_CHAT_LEN); - req.arg.addbuddy.text[MAX_BUDDY_CHAT_LEN-1] = 0; + wcslcpy(req.arg.addbuddy.text, buddyAddstr.str(), MAX_BUDDY_CHAT_LEN); TheGameSpyBuddyMessageQueue->addRequest(req); } } diff --git a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLBuddyOverlay.cpp b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLBuddyOverlay.cpp index d0495d7e92..c99b32e55e 100644 --- a/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLBuddyOverlay.cpp +++ b/Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLBuddyOverlay.cpp @@ -304,8 +304,7 @@ WindowMsgHandledType BuddyControlSystem( GameWindow *window, UnsignedInt msg, // Send the message BuddyRequest req; req.buddyRequestType = BuddyRequest::BUDDYREQUEST_MESSAGE; - wcsncpy(req.arg.message.text, txtInput.str(), MAX_BUDDY_CHAT_LEN); - req.arg.message.text[MAX_BUDDY_CHAT_LEN-1] = 0; + wcslcpy(req.arg.message.text, txtInput.str(), MAX_BUDDY_CHAT_LEN); req.arg.message.recipient = selectedProfile; TheGameSpyBuddyMessageQueue->addRequest(req); @@ -1184,8 +1183,7 @@ void RequestBuddyAdd(Int profileID, AsciiString nick) req.arg.addbuddy.id = profileID; UnicodeString buddyAddstr; buddyAddstr = TheGameText->fetch("GUI:BuddyAddReq"); - wcsncpy(req.arg.addbuddy.text, buddyAddstr.str(), MAX_BUDDY_CHAT_LEN); - req.arg.addbuddy.text[MAX_BUDDY_CHAT_LEN-1] = 0; + wcslcpy(req.arg.addbuddy.text, buddyAddstr.str(), MAX_BUDDY_CHAT_LEN); TheGameSpyBuddyMessageQueue->addRequest(req); UnicodeString s; diff --git a/Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp b/Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp index f0d08b7588..39f8f3469b 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp @@ -512,8 +512,7 @@ void BuddyThreadClass::messageCallback( GPConnection *con, GPRecvBuddyMessageArg gpGetInfo( con, arg->profile, GP_CHECK_CACHE, GP_BLOCKING, (GPCallback)getNickForMessage, &messageResponse); std::wstring s = MultiByteToWideCharSingleLine( arg->message ); - wcsncpy(messageResponse.arg.message.text, s.c_str(), MAX_BUDDY_CHAT_LEN); - messageResponse.arg.message.text[MAX_BUDDY_CHAT_LEN-1] = 0; + wcslcpy(messageResponse.arg.message.text, s.c_str(), MAX_BUDDY_CHAT_LEN); messageResponse.arg.message.date = arg->date; DEBUG_LOG(("Got a buddy message from %d [%ls]", arg->profile, s.c_str())); TheGameSpyBuddyMessageQueue->addResponse( messageResponse ); @@ -629,8 +628,7 @@ void BuddyThreadClass::requestCallback( GPConnection *con, GPRecvBuddyRequestArg gpGetInfo( con, arg->profile, GP_CHECK_CACHE, GP_BLOCKING, (GPCallback)getInfoResponseForRequest, &response); std::wstring s = MultiByteToWideCharSingleLine( arg->reason ); - wcsncpy(response.arg.request.text, s.c_str(), GP_REASON_LEN); - response.arg.request.text[GP_REASON_LEN-1] = 0; + wcslcpy(response.arg.request.text, s.c_str(), GP_REASON_LEN); TheGameSpyBuddyMessageQueue->addResponse( response ); } diff --git a/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp b/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp index 43a35249be..d2ab560dae 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/LANAPI.cpp @@ -519,8 +519,7 @@ void LANAPI::update( void ) LANMessage msg; fillInLANMessage( &msg ); msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_LEAVE; - wcsncpy(msg.name, m_currentGame->getPlayerName(0).str(), g_lanPlayerNameLength); - msg.name[g_lanPlayerNameLength] = 0; + wcslcpy(msg.name, m_currentGame->getPlayerName(0).str(), ARRAY_SIZE(msg.name)); handleRequestGameLeave(&msg, m_currentGame->getIP(0)); UnicodeString text; text = TheGameText->fetch("LAN:HostNotResponding"); @@ -538,8 +537,7 @@ void LANAPI::update( void ) UnicodeString theStr; theStr.format(TheGameText->fetch("LAN:PlayerDropped"), m_currentGame->getPlayerName(p).str()); msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_LEAVE; - wcsncpy(msg.name, m_currentGame->getPlayerName(p).str(), g_lanPlayerNameLength); - msg.name[g_lanPlayerNameLength] = 0; + wcslcpy(msg.name, m_currentGame->getPlayerName(p).str(), ARRAY_SIZE(msg.name)); handleRequestGameLeave(&msg, m_currentGame->getIP(p)); OnChat(UnicodeString::TheEmptyString, m_localIP, theStr, LANCHAT_SYSTEM); } @@ -670,8 +668,7 @@ void LANAPI::RequestGameJoinDirectConnect(UnsignedInt ipaddress) msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_INFO; fillInLANMessage(&msg); msg.PlayerInfo.ip = GetLocalIP(); - wcsncpy(msg.PlayerInfo.playerName, m_name.str(), m_name.getLength()); - msg.PlayerInfo.playerName[m_name.getLength()] = 0; + wcslcpy(msg.PlayerInfo.playerName, m_name.str(), ARRAY_SIZE(msg.PlayerInfo.playerName)); sendMessage(&msg, ipaddress); @@ -684,8 +681,7 @@ void LANAPI::RequestGameLeave( void ) LANMessage msg; msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_LEAVE; fillInLANMessage( &msg ); - wcsncpy(msg.GameToLeave.gameName, (m_currentGame)?m_currentGame->getName().str():L"", g_lanGameNameLength); - msg.GameToLeave.gameName[g_lanGameNameLength] = 0; + wcslcpy(msg.PlayerInfo.playerName, m_name.str(), ARRAY_SIZE(msg.PlayerInfo.playerName)); sendMessage(&msg); m_transport->update(); // Send immediately, before OnPlayerLeave below resets everything. @@ -717,8 +713,7 @@ void LANAPI::RequestGameAnnounce( void ) AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options)); - wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameInfo.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName)); reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); reply.GameInfo.isDirectConnect = m_currentGame->getIsDirectConnect(); @@ -736,8 +731,7 @@ void LANAPI::RequestAccept( void ) fillInLANMessage( &msg ); msg.LANMessageType = LANMessage::MSG_SET_ACCEPT; msg.Accept.isAccepted = true; - wcsncpy(msg.Accept.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - msg.Accept.gameName[g_lanGameNameLength] = 0; + wcslcpy(msg.Accept.gameName, m_currentGame->getName().str(), ARRAY_SIZE(msg.Accept.gameName)); sendMessage(&msg); } @@ -750,8 +744,7 @@ void LANAPI::RequestHasMap( void ) fillInLANMessage( &msg ); msg.LANMessageType = LANMessage::MSG_MAP_AVAILABILITY; msg.MapStatus.hasMap = m_currentGame->getSlot(m_currentGame->getLocalSlotNum())->hasMap(); - wcsncpy(msg.MapStatus.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - msg.MapStatus.gameName[g_lanGameNameLength] = 0; + wcslcpy(msg.MapStatus.gameName, m_currentGame->getName().str(), ARRAY_SIZE(msg.MapStatus.gameName)); CRC mapNameCRC; //mapNameCRC.computeCRC(m_currentGame->getMap().str(), m_currentGame->getMap().getLength()); AsciiString portableMapName = TheGameState->realMapPathToPortableMapPath(m_currentGame->getMap()); @@ -788,12 +781,10 @@ void LANAPI::RequestChat( UnicodeString message, ChatType format ) { LANMessage msg; fillInLANMessage( &msg ); - wcsncpy(msg.Chat.gameName, (m_currentGame)?m_currentGame->getName().str():L"", g_lanGameNameLength); - msg.Chat.gameName[g_lanGameNameLength] = 0; + wcslcpy(msg.Chat.gameName, (m_currentGame) ? m_currentGame->getName().str() : L"", ARRAY_SIZE(msg.Chat.gameName)); msg.LANMessageType = LANMessage::MSG_CHAT; msg.Chat.chatType = format; - wcsncpy(msg.Chat.message, message.str(), g_lanMaxChatLength); - msg.Chat.message[g_lanMaxChatLength] = 0; + wcslcpy(msg.Chat.message, message.str(), ARRAY_SIZE(msg.Chat.message)); sendMessage(&msg); OnChat(m_name, m_localIP, message, format); @@ -943,8 +934,7 @@ void LANAPI::RequestGameCreate( UnicodeString gameName, Bool isDirectConnect ) //RequestSlotList(); /* LANMessage msg; - wcsncpy(msg.name, m_name.str(), g_lanPlayerNameLength); - msg.name[g_lanPlayerNameLength] = 0; + wcslcpy(msg.name, m_name.str(), ARRAY_SIZE(msg.name)); wcscpy(msg.GameInfo.gameName, myGame->getName().str()); for (player=0; playergetPlayerName(player).str(), g_lanPlayerNameLength); - reply.GameInfo.name[player][g_lanPlayerNameLength] = 0; + wcslcpy(reply.GameInfo.name[player], m_currentGame->getPlayerName(player).str(), ARRAY_SIZE(reply.GameInfo.name[player])); reply.GameInfo.ip[player] = m_currentGame->getIP(player); reply.GameInfo.playerAccepted[player] = m_currentGame->getSlot(player)->isAccepted(); } - wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameInfo.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName)); reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); sendMessage(&reply); @@ -1082,8 +1069,7 @@ void LANAPI::fillInLANMessage( LANMessage *msg ) if (!msg) return; - wcsncpy(msg->name, m_name.str(), g_lanPlayerNameLength); - msg->name[g_lanPlayerNameLength] = 0; + wcslcpy(msg->name, m_name.str(), ARRAY_SIZE(msg->name)); strlcpy(msg->userName, m_userName.str(), ARRAY_SIZE(msg->userName)); strlcpy(msg->hostName, m_hostName.str(), ARRAY_SIZE(msg->hostName)); } diff --git a/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp index ce16788bd4..9f8876f096 100644 --- a/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp +++ b/Generals/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp @@ -63,8 +63,7 @@ void LANAPI::handleRequestLocations( LANMessage *msg, UnsignedInt senderIP ) reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GenerateGameOptionsString(); strlcpy(reply.GameInfo.options, gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options)); - wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameInfo.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName)); reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); sendMessage(&reply); @@ -194,8 +193,7 @@ void LANAPI::handleRequestGameInfo( LANMessage *msg, UnsignedInt senderIP ) AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options)); - wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameInfo.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName)); reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); reply.GameInfo.isDirectConnect = m_currentGame->getIsDirectConnect(); @@ -314,8 +312,7 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP ) { // OK, add him in. reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT; - wcsncpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameJoined.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameJoined.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameJoined.gameName)); reply.GameJoined.slotPosition = player; reply.GameJoined.gameIP = m_localIP; reply.GameJoined.playerIP = senderIP; @@ -339,8 +336,7 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP ) if (canJoin && player == MAX_SLOTS) { reply.LANMessageType = LANMessage::MSG_JOIN_DENY; - wcsncpy(reply.GameNotJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameNotJoined.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameNotJoined.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameNotJoined.gameName)); reply.GameNotJoined.reason = LANAPIInterface::RET_GAME_FULL; reply.GameNotJoined.gameIP = m_localIP; reply.GameNotJoined.playerIP = senderIP; diff --git a/GeneralsMD/Code/GameEngine/Include/Common/Language.h b/GeneralsMD/Code/GameEngine/Include/Common/Language.h index b55884f6c7..cc1b80e263 100644 --- a/GeneralsMD/Code/GameEngine/Include/Common/Language.h +++ b/GeneralsMD/Code/GameEngine/Include/Common/Language.h @@ -76,7 +76,6 @@ typedef enum } LanguageID; #define GameStrcpy wcscpy -#define GameStrncpy wcsncpy #define GameStrlen wcslen #define GameStrcat wcscat #define GameStrcmp wcscmp diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp index d7d4c1db4e..51b3f1cd76 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ScoreScreen.cpp @@ -632,8 +632,7 @@ WindowMsgHandledType ScoreScreenSystem( GameWindow *window, UnsignedInt msg, req.arg.addbuddy.id = playerID; UnicodeString buddyAddstr; buddyAddstr = TheGameText->fetch("GUI:BuddyAddReq"); - wcsncpy(req.arg.addbuddy.text, buddyAddstr.str(), MAX_BUDDY_CHAT_LEN); - req.arg.addbuddy.text[MAX_BUDDY_CHAT_LEN-1] = 0; + wcslcpy(req.arg.addbuddy.text, buddyAddstr.str(), MAX_BUDDY_CHAT_LEN); TheGameSpyBuddyMessageQueue->addRequest(req); } } diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLBuddyOverlay.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLBuddyOverlay.cpp index 06b6516fd8..942819c867 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLBuddyOverlay.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/WOLBuddyOverlay.cpp @@ -304,8 +304,7 @@ WindowMsgHandledType BuddyControlSystem( GameWindow *window, UnsignedInt msg, // Send the message BuddyRequest req; req.buddyRequestType = BuddyRequest::BUDDYREQUEST_MESSAGE; - wcsncpy(req.arg.message.text, txtInput.str(), MAX_BUDDY_CHAT_LEN); - req.arg.message.text[MAX_BUDDY_CHAT_LEN-1] = 0; + wcslcpy(req.arg.message.text, txtInput.str(), MAX_BUDDY_CHAT_LEN); req.arg.message.recipient = selectedProfile; TheGameSpyBuddyMessageQueue->addRequest(req); @@ -1185,8 +1184,7 @@ void RequestBuddyAdd(Int profileID, AsciiString nick) req.arg.addbuddy.id = profileID; UnicodeString buddyAddstr; buddyAddstr = TheGameText->fetch("GUI:BuddyAddReq"); - wcsncpy(req.arg.addbuddy.text, buddyAddstr.str(), MAX_BUDDY_CHAT_LEN); - req.arg.addbuddy.text[MAX_BUDDY_CHAT_LEN-1] = 0; + wcslcpy(req.arg.addbuddy.text, buddyAddstr.str(), MAX_BUDDY_CHAT_LEN); TheGameSpyBuddyMessageQueue->addRequest(req); UnicodeString s; diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp index 75905f2e09..a31644dca0 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp @@ -512,8 +512,7 @@ void BuddyThreadClass::messageCallback( GPConnection *con, GPRecvBuddyMessageArg gpGetInfo( con, arg->profile, GP_CHECK_CACHE, GP_BLOCKING, (GPCallback)getNickForMessage, &messageResponse); std::wstring s = MultiByteToWideCharSingleLine( arg->message ); - wcsncpy(messageResponse.arg.message.text, s.c_str(), MAX_BUDDY_CHAT_LEN); - messageResponse.arg.message.text[MAX_BUDDY_CHAT_LEN-1] = 0; + wcslcpy(messageResponse.arg.message.text, s.c_str(), MAX_BUDDY_CHAT_LEN); messageResponse.arg.message.date = arg->date; DEBUG_LOG(("Got a buddy message from %d [%ls]", arg->profile, s.c_str())); TheGameSpyBuddyMessageQueue->addResponse( messageResponse ); @@ -629,8 +628,7 @@ void BuddyThreadClass::requestCallback( GPConnection *con, GPRecvBuddyRequestArg gpGetInfo( con, arg->profile, GP_CHECK_CACHE, GP_BLOCKING, (GPCallback)getInfoResponseForRequest, &response); std::wstring s = MultiByteToWideCharSingleLine( arg->reason ); - wcsncpy(response.arg.request.text, s.c_str(), GP_REASON_LEN); - response.arg.request.text[GP_REASON_LEN-1] = 0; + wcslcpy(response.arg.request.text, s.c_str(), GP_REASON_LEN); TheGameSpyBuddyMessageQueue->addResponse( response ); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp index 4722096271..e851a8e1ab 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPI.cpp @@ -519,8 +519,7 @@ void LANAPI::update( void ) LANMessage msg; fillInLANMessage( &msg ); msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_LEAVE; - wcsncpy(msg.name, m_currentGame->getPlayerName(0).str(), g_lanPlayerNameLength); - msg.name[g_lanPlayerNameLength] = 0; + wcslcpy(msg.name, m_currentGame->getPlayerName(0).str(), ARRAY_SIZE(msg.name)); handleRequestGameLeave(&msg, m_currentGame->getIP(0)); UnicodeString text; text = TheGameText->fetch("LAN:HostNotResponding"); @@ -538,8 +537,7 @@ void LANAPI::update( void ) UnicodeString theStr; theStr.format(TheGameText->fetch("LAN:PlayerDropped"), m_currentGame->getPlayerName(p).str()); msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_LEAVE; - wcsncpy(msg.name, m_currentGame->getPlayerName(p).str(), g_lanPlayerNameLength); - msg.name[g_lanPlayerNameLength] = 0; + wcslcpy(msg.name, m_currentGame->getPlayerName(p).str(), ARRAY_SIZE(msg.name)); handleRequestGameLeave(&msg, m_currentGame->getIP(p)); OnChat(UnicodeString::TheEmptyString, m_localIP, theStr, LANCHAT_SYSTEM); } @@ -670,8 +668,7 @@ void LANAPI::RequestGameJoinDirectConnect(UnsignedInt ipaddress) msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_INFO; fillInLANMessage(&msg); msg.PlayerInfo.ip = GetLocalIP(); - wcsncpy(msg.PlayerInfo.playerName, m_name.str(), m_name.getLength()); - msg.PlayerInfo.playerName[m_name.getLength()] = 0; + wcslcpy(msg.PlayerInfo.playerName, m_name.str(), ARRAY_SIZE(msg.PlayerInfo.playerName)); sendMessage(&msg, ipaddress); @@ -684,8 +681,7 @@ void LANAPI::RequestGameLeave( void ) LANMessage msg; msg.LANMessageType = LANMessage::MSG_REQUEST_GAME_LEAVE; fillInLANMessage( &msg ); - wcsncpy(msg.GameToLeave.gameName, (m_currentGame)?m_currentGame->getName().str():L"", g_lanGameNameLength); - msg.GameToLeave.gameName[g_lanGameNameLength] = 0; + wcslcpy(msg.GameToLeave.gameName, (m_currentGame)?m_currentGame->getName().str():L"", ARRAY_SIZE(msg.GameToLeave.gameName)); sendMessage(&msg); m_transport->update(); // Send immediately, before OnPlayerLeave below resets everything. @@ -717,8 +713,7 @@ void LANAPI::RequestGameAnnounce( void ) AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameOptions.options)); - wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameInfo.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName)); reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); reply.GameInfo.isDirectConnect = m_currentGame->getIsDirectConnect(); @@ -736,8 +731,7 @@ void LANAPI::RequestAccept( void ) fillInLANMessage( &msg ); msg.LANMessageType = LANMessage::MSG_SET_ACCEPT; msg.Accept.isAccepted = true; - wcsncpy(msg.Accept.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - msg.Accept.gameName[g_lanGameNameLength] = 0; + wcslcpy(msg.Accept.gameName, m_currentGame->getName().str(), ARRAY_SIZE(msg.Accept.gameName)); sendMessage(&msg); } @@ -750,8 +744,7 @@ void LANAPI::RequestHasMap( void ) fillInLANMessage( &msg ); msg.LANMessageType = LANMessage::MSG_MAP_AVAILABILITY; msg.MapStatus.hasMap = m_currentGame->getSlot(m_currentGame->getLocalSlotNum())->hasMap(); - wcsncpy(msg.MapStatus.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - msg.MapStatus.gameName[g_lanGameNameLength] = 0; + wcslcpy(msg.MapStatus.gameName, m_currentGame->getName().str(), ARRAY_SIZE(msg.MapStatus.gameName)); CRC mapNameCRC; //mapNameCRC.computeCRC(m_currentGame->getMap().str(), m_currentGame->getMap().getLength()); AsciiString portableMapName = TheGameState->realMapPathToPortableMapPath(m_currentGame->getMap()); @@ -788,12 +781,10 @@ void LANAPI::RequestChat( UnicodeString message, ChatType format ) { LANMessage msg; fillInLANMessage( &msg ); - wcsncpy(msg.Chat.gameName, (m_currentGame)?m_currentGame->getName().str():L"", g_lanGameNameLength); - msg.Chat.gameName[g_lanGameNameLength] = 0; + wcslcpy(msg.Chat.gameName, (m_currentGame)?m_currentGame->getName().str():L"", ARRAY_SIZE(msg.Chat.gameName)); msg.LANMessageType = LANMessage::MSG_CHAT; msg.Chat.chatType = format; - wcsncpy(msg.Chat.message, message.str(), g_lanMaxChatLength); - msg.Chat.message[g_lanMaxChatLength] = 0; + wcslcpy(msg.Chat.message, message.str(), ARRAY_SIZE(msg.Chat.message)); sendMessage(&msg); OnChat(m_name, m_localIP, message, format); @@ -942,8 +933,7 @@ void LANAPI::RequestGameCreate( UnicodeString gameName, Bool isDirectConnect ) //RequestSlotList(); /* LANMessage msg; - wcsncpy(msg.name, m_name.str(), g_lanPlayerNameLength); - msg.name[g_lanPlayerNameLength] = 0; + wcslcpy(msg.name, m_name.str(), ARRAY_SIZE(msg.name)); wcscpy(msg.GameInfo.gameName, myGame->getName().str()); for (player=0; playergetPlayerName(player).str(), g_lanPlayerNameLength); - reply.GameInfo.name[player][g_lanPlayerNameLength] = 0; + wcslcpy(reply.GameInfo.name[player], m_currentGame->getPlayerName(player).str(), ARRAY_SIZE(reply.GameInfo.name[player])); reply.GameInfo.ip[player] = m_currentGame->getIP(player); reply.GameInfo.playerAccepted[player] = m_currentGame->getSlot(player)->isAccepted(); } - wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameInfo.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName)); reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); sendMessage(&reply); @@ -1081,8 +1068,7 @@ void LANAPI::fillInLANMessage( LANMessage *msg ) if (!msg) return; - wcsncpy(msg->name, m_name.str(), g_lanPlayerNameLength); - msg->name[g_lanPlayerNameLength] = 0; + wcslcpy(msg->name, m_name.str(), ARRAY_SIZE(msg->name)); strlcpy(msg->userName, m_userName.str(), ARRAY_SIZE(msg->userName)); strlcpy(msg->hostName, m_hostName.str(), ARRAY_SIZE(msg->hostName)); } diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp index 5291b6b784..d2244cc77a 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/LANAPIhandlers.cpp @@ -63,8 +63,7 @@ void LANAPI::handleRequestLocations( LANMessage *msg, UnsignedInt senderIP ) reply.LANMessageType = LANMessage::MSG_GAME_ANNOUNCE; AsciiString gameOpts = GenerateGameOptionsString(); strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options)); - wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameInfo.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName)); reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); sendMessage(&reply); @@ -194,8 +193,7 @@ void LANAPI::handleRequestGameInfo( LANMessage *msg, UnsignedInt senderIP ) AsciiString gameOpts = GameInfoToAsciiString(m_currentGame); strlcpy(reply.GameInfo.options,gameOpts.str(), ARRAY_SIZE(reply.GameInfo.options)); - wcsncpy(reply.GameInfo.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameInfo.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameInfo.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameInfo.gameName)); reply.GameInfo.inProgress = m_currentGame->isGameInProgress(); reply.GameInfo.isDirectConnect = m_currentGame->getIsDirectConnect(); @@ -315,8 +313,7 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP ) { // OK, add him in. reply.LANMessageType = LANMessage::MSG_JOIN_ACCEPT; - wcsncpy(reply.GameJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameJoined.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameJoined.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameJoined.gameName)); reply.GameJoined.slotPosition = player; reply.GameJoined.gameIP = m_localIP; reply.GameJoined.playerIP = senderIP; @@ -340,8 +337,7 @@ void LANAPI::handleRequestJoin( LANMessage *msg, UnsignedInt senderIP ) if (canJoin && player == MAX_SLOTS) { reply.LANMessageType = LANMessage::MSG_JOIN_DENY; - wcsncpy(reply.GameNotJoined.gameName, m_currentGame->getName().str(), g_lanGameNameLength); - reply.GameNotJoined.gameName[g_lanGameNameLength] = 0; + wcslcpy(reply.GameNotJoined.gameName, m_currentGame->getName().str(), ARRAY_SIZE(reply.GameNotJoined.gameName)); reply.GameNotJoined.reason = LANAPIInterface::RET_GAME_FULL; reply.GameNotJoined.gameIP = m_localIP; reply.GameNotJoined.playerIP = senderIP;