本文整理汇总了C++中sf::TcpSocket::send方法的典型用法代码示例。如果您正苦于以下问题:C++ TcpSocket::send方法的具体用法?C++ TcpSocket::send怎么用?C++ TcpSocket::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sf::TcpSocket
的用法示例。
在下文中一共展示了TcpSocket::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getAccountName
void ServerController::getAccountName(sf::Packet &packet, sf::TcpSocket &client)
{
sf::Packet response;
std::string username, target, first, last;
bool exists = false;
packet >> username >> target;
std::cout << "Attempting to find full name for User " << target << std::endl;
// authenticate request
if (checkAccount(username) == -1)
{
return;
}
int targetIndex = checkAccount(target);
if (targetIndex != -1)
{
std::cout << "User does exist" << std::endl;
first = data.accounts[targetIndex].getFirstName();
last = data.accounts[targetIndex].getLastName();
exists = true;
response << exists << first << last;
client.send(response);
return;
}
std::cout << "User does not exist" << std::endl;
response << exists;
client.send(response);
}
示例2: addMember
void ServerController::addMember(sf::Packet &packet, sf::TcpSocket &client, Account::AccessLevel level)
{
sf::Packet response;
std::string username, conference, targetUser;
packet >> username >> conference >> targetUser;
bool success = false;
int findIndex = checkAccount(username);
int targetIndex = checkAccount(targetUser);
int confIndex = checkConference(conference);
if (findIndex == -1 || targetIndex == -1 || confIndex == -1)
{
success = false;
response << success;
client.send(response);
return;
}
// add access to the conference in the target user's accessmap
data.accounts[targetIndex].addAccess(conference, level);
if (level == Account::Access_Reviewer)
{
data.conferences[confIndex].addReviewer(targetUser);
}
// add welcome notification to the user
addNotification(targetUser, "Welcome to " + conference + "!");
success = true;
response << success;
client.send(response);
data.saveAccounts();
data.saveConferences();
}
示例3: checkPaperAlloc
void ServerController::checkPaperAlloc(sf::Packet &packet, sf::TcpSocket &client)
{
sf::Packet response;
std::string conference, paperTitle;
int rev_count;
bool result = false;
packet >> conference >> paperTitle;
int confIndex = checkConference(conference);
if(confIndex == -1)
{
return;
}
int max_rev = data.conferences[confIndex].getMaxPaperReviewers();
for (int i = 0; i < (int)data.submissions.size(); i++)
{
if (data.submissions[i].getConference() == conference)
{
if(data.submissions[i].getTitle() == paperTitle)
{
rev_count = data.submissions[i].getReviewerCount();
if (rev_count < max_rev)
{
result = true;
break;
}
}
}
}
response << result;
client.send(response);
}
示例4: loginAccount
void ServerController::loginAccount(sf::Packet &packet, sf::TcpSocket &client){
sf::Packet validate;
std::string username, password;
bool valid = false;
packet >> username >> password;
int findIndex = checkAccount(username,password);
if (findIndex != -1)
{
valid = true;
}
if (valid)
{
// set the user as logged in
data.accounts[findIndex].startSession();
data.addLog(username + " has logged in.");
data.saveAccounts();
}
validate << valid;
client.send(validate);
}
示例5: getConfSubmissions
void ServerController::getConfSubmissions(sf::Packet &packet, sf::TcpSocket &client)
{
sf::Packet response;
std::string conference;
std::vector<std::string> submission;
packet >> conference;
for (int i = 0; i < (int)data.submissions.size(); i++)
{
if(data.submissions[i].getConference() == conference)
{
submission.push_back(data.submissions[i].getTitle());
}
}
response << (int)submission.size();
for (int i = 0; i < (int)submission.size(); i++)
{
response << submission[i];
}
client.send(response);
}
示例6: getReview
void ServerController::getReview(sf::Packet &packet, sf::TcpSocket &client)
{
sf::Packet response;
std::string username, conf, id;
Review aReview;
bool found = false;
packet >> username >> conf >> id;
// authenticate request
if (checkAccount(username) == -1)
{
return;
}
// authenticate conference
if (checkConference(conf) == -1)
{
return;
}
// find review with id
std::vector<Review>::iterator it;
for (it = data.reviews.begin(); it != data.reviews.end(); ++it)
{
if (it->getReviewID() == id)
{
aReview = *it;
found = true;
break;
}
}
response << found;
if (found)
{
response << aReview;
}
client.send(response);
}
示例7: sendRegisteringToken
void Client::sendRegisteringToken(const std::string& name, const std::string& password, sf::TcpSocket& socket)
{
sf::Packet packet;
packet << TransferType::REGISTERING << name << password;
if(socket.send(packet) != sf::Socket::Done)
throw std::runtime_error("sending packet failed.");
// Receive the server response
socket.receive(packet);
TransferType response;
packet >> response;
switch(response)
{
case TransferType::USERNAME_NOT_AVAILABLE:
throw std::runtime_error("the username " + name + " is not available.");
case TransferType::FAILED_TO_REGISTER:
throw std::runtime_error("the server failed to register your account.");
case TransferType::ACKNOWLEDGE:
return;
default:
throw std::runtime_error("unidentified server response.");
}
}
示例8: getConferenceSubs
void ServerController::getConferenceSubs(sf::Packet &packet, sf::TcpSocket &client)
{
sf::Packet response;
std::string conf;
packet >> conf;
// add all matching submissions with this conference name
std::vector<std::string> results;
std::vector<Submission>::iterator it;
for (it = data.submissions.begin(); it != data.submissions.end(); ++it)
{
if (it->getConference() == conf)
{
results.push_back(it->getTitle());
}
}
// pack into the response packet
response << (int)results.size();
for (int i = 0; i < (int)results.size(); ++i)
{
response << results[i];
}
client.send(response);
}
示例9: doSwitchMode
void doSwitchMode(Mode mode){
arduino.connect(ip, port);
if (mode != currentMode){
currentMode = mode;
char data;
switch (mode){
case Mode::SolidWhite: data = (char) 0;
break;
case Mode::Marquee: data = (char) 1;
break;
case Mode::ColorCycle: data = (char) 2;
break;
case Mode::Pew: data = (char) 3;
break;
default: break;
}
char* dataPointer = &data;
arduino.send(dataPointer, sizeof(data));
}
arduino.disconnect();
}
示例10: getComments
void ServerController::getComments(sf::Packet &packet, sf::TcpSocket &client)
{
std::string conference, paperTitle;
sf::Packet response;
packet >> conference >> paperTitle;
std::vector<Comment> comments;
for (int i = 0; i < (int)data.submissions.size(); i++)
{
if (data.submissions[i].getConference() == conference)
{
if (data.submissions[i].getTitle() == paperTitle)
{
data.submissions[i].getComments(comments);
}
}
}
response << (int)comments.size();
for (int i = 0; i < (int)comments.size(); i++)
{
response << comments[i];
}
client.send(response);
}
示例11: getLimit
void ServerController::getLimit(sf::Packet &packet, sf::TcpSocket &client, const std::string &mode)
{
sf::Packet response;
std::string username, conference;
sf::Int16 limit;
packet >> username >> conference >> limit;
// authenticate request
int accIndex = checkAccount(username);
if (accIndex == -1)
{
return;
}
// authenticate conference
int confIndex = checkConference(conference);
if (confIndex == -1)
{
return;
}
if (mode == "ALLOCATED")
{
limit = data.conferences[confIndex].getMaxReviewedPapers();
}
else if (mode == "PAPERREV")
{
limit = data.conferences[confIndex].getMaxPaperReviewers();
}
response << limit;
client.send(response);
}
示例12: checkReviewed
void ServerController::checkReviewed(sf::Packet &packet, sf::TcpSocket &client)
{
sf::Packet response;
std::string user, conference, paper, first, last;
packet >> user >> conference >> paper;
// authenticate request
int findIndex = checkAccount(user);
if (findIndex != -1)
{
first = data.accounts[findIndex].getFirstName();
last = data.accounts[findIndex].getLastName();
}
bool hasReviewed = false;
for (int i = 0; i < (int)data.reviews.size(); ++i)
{
if (data.reviews[i].getTitle() == paper && data.reviews[i].getConference() == conference)
{
if (data.reviews[i].getPCMember() == (first + " " + last))
{
hasReviewed = true;
break;
}
}
}
response << hasReviewed;
client.send(response);
}
示例13: paperSubmission
void ServerController::paperSubmission(sf::Packet &packet, sf::TcpSocket &client)
{
sf::Packet response;
Submission sub;
bool exists = false;
std::string username, conference, title;
packet >> username;
int findIndex = checkAccount(username); //get Account index
if (findIndex == -1)
{
return; // ignore request if user is not found
}
packet >> sub;
conference = sub.getConference();
title = sub.getTitle();
int confIndex = checkConference(conference);
if (confIndex == -1)
{
return; // ignore request if conference is not found
}
if (data.accounts[findIndex].getAccess(conference) < Account::Access_Author)
{
return; // ignore request if user is not at least an author of that conference
}
// check conference is in submission phase
if (data.conferences[confIndex].getCurrentPhase() != "Submission")
{
return; // ignore request if conference is not accepting submissions
}
// check that the paper does not already exist
if (checkSubmission(title, conference) == -1)
{
// set the papers university to the submitting author
sub.setUniversity(data.accounts[findIndex].getUniversity());
// add the submitting author as an author
std::string firstname = data.accounts[findIndex].getFirstName();
std::string lastname = data.accounts[findIndex].getLastName();
sub.addAuthor(firstname, lastname);
data.submissions.push_back(sub);
data.saveSubmissions();
data.addLog("Paper was submitted: " + title + " by " + username + " for conference " + conference);
addNotification(username, "You submitted a paper '" + title + "' to " + conference);
notifyConference(conference,
username + " submitted a paper '" + title + "' to " + conference,
Account::Access_Chairman);
}
else
{
exists = true;
}
response << exists;
client.send(response);
}
示例14: sync
void Player::sync(sf::TcpSocket & socket)
{
if (mEntity)
{
sf::Packet packet;
packet << Cl::GameEvent << GameEvent::MoveEntity << mEntity->getID() << mEntity->getPosition().x << mEntity->getPosition().y;
socket.send(packet);
packet.clear();
packet << Cl::GameEvent << GameEvent::RotateEntity << mEntity->getID() << mEntity->getRotation();
socket.send(packet);
if (mSkill1)
{
if (mEntity->getType() == Entity::Type::Human)
{
sf::Packet packet;
packet << Cl::GameEvent << GameEvent::ShootBullet <<mEntity->getID() << mEntity->getRotation() << mEntity->getCenter().x << mEntity->getCenter().y;
socket.send(packet);
}
else if (mEntity->getType() == Entity::Type::Zombie)
{
std::cout << "Zombie melee attack\n";
sf::Packet packet;
packet << Cl::GameEvent << GameEvent::ZombieMeleeAttack;
Zombie * z = static_cast<Zombie*>(mEntity);
sf::FloatRect rect = z->getMeeleAttackBox();
packet << rect.top << rect.left << rect.width << rect.height;
std::cout << rect.top << ", " << rect.left << ", " << rect.width << ". " << rect.height << "\n";
socket.send(packet);
}
}
}
}
示例15: trySendPacket
bool trySendPacket(sf::Packet mPacket)
{
if(!busy) { ssvu::lo("ManagedSocket") << "Couldn't send packet - not busy" << std::endl; return false; }
for(int i{0}; i < 5; ++i)
{
if(busy && socket.send(mPacket) == sf::Socket::Done) { onPacketSent(mPacket); return true; }
std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
ssvu::lo("ManagedSocket") << "Couldn't send packet - disconnecting" << std::endl;
disconnect();
return false;
}