mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
refs #22
Fix leading space and trailing LF in real name Use proper const char* to const char* copy in NetworkVatlib::initiateConnection()
This commit is contained in:
@@ -154,7 +154,7 @@ void Client::setCallsignCmd(QTextStream& args)
|
||||
|
||||
void Client::setRealNameCmd(QTextStream& args)
|
||||
{
|
||||
emit setRealName(args.readAll());
|
||||
emit setRealName(args.readLine().mid(1)); //readLine returns the entire line up to, but excluding, the LF character. mid(int) is the QString equivilent of a substring(start), used here to remove a space
|
||||
}
|
||||
|
||||
void Client::initiateConnectionCmd(QTextStream&)
|
||||
|
||||
@@ -166,12 +166,23 @@ namespace BlackCore
|
||||
{
|
||||
try
|
||||
{
|
||||
//Proper way to copy a const char* to a const char*. Copy it to a char* then assign the char* to the const char*
|
||||
const size_t len1 = strlen(m_callsign.toStdString().c_str()); //Get the length
|
||||
char* tmp1 = new char[len1 + 1]; //Allocate the char*
|
||||
strncpy(tmp1, m_callsign.toStdString().c_str(), len1); //Copy the const char* to the char*
|
||||
tmp1[len1] = '\0'; //Insurance of null termination
|
||||
|
||||
const size_t len2 = strlen(m_realname.toStdString().c_str());
|
||||
char* tmp2 = new char[len2 + 1];
|
||||
strncpy(tmp2, m_realname.toStdString().c_str(), len2);
|
||||
tmp2[len2] = '\0';
|
||||
|
||||
Cvatlib_Network::PilotConnectionInfo info;
|
||||
info.callsign = m_callsign.toStdString().c_str();
|
||||
info.name = m_realname.toStdString().c_str();
|
||||
info.callsign = tmp1; //Assign char* to const char*
|
||||
info.name = tmp2;
|
||||
info.rating = Cvatlib_Network::pilotRating_Unknown; //TODO
|
||||
info.sim = Cvatlib_Network::simType_XPlane; //TODO
|
||||
|
||||
|
||||
m_net->SetPilotLoginInfo(m_serverHost.toStdString().c_str(), m_serverPort,
|
||||
m_username.toStdString().c_str(), m_password.toStdString().c_str(), info);
|
||||
m_net->ConnectAndLogon();
|
||||
|
||||
Reference in New Issue
Block a user