本文整理汇总了C++中Package::getPackageType方法的典型用法代码示例。如果您正苦于以下问题:C++ Package::getPackageType方法的具体用法?C++ Package::getPackageType怎么用?C++ Package::getPackageType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package::getPackageType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void* ServerThread::run() {
while (true) {
//TODO main loop thread, process query by package
try {
char buff[512];
memset(buff, 0, sizeof(buff));
socket->receive(buff, sizeof(buff), MSG_PEEK);
Package currentPackage = buff;
/*char timeBuff[100];
memset(timeBuff, 0, sizeof(timeBuff));
time_t packageTime = currentPackage.getPackageTime();
strftime(timeBuff, sizeof(timeBuff), "%T", gmtime(&packageTime));
cout << "--- Received package stats --- " << endl
<< "packageNum: " << currentPackage.getPackageType() << endl
<< "packageTime: " << timeBuff << endl
<< "--- End of package stats --- " << endl;*/
if(currentPackage.getPackageType() == Protocol::userSignup) {
/* Signup */
/* Receive packet contains username password */
// flush first
memset(buff, 0, sizeof(buff));
socket->receive(buff, sizeof(buff));
UserInitPackage package = buff;
string username = package.getUserName();
string password = package.getUserPassword();
if(Group::isGroupExists(username)) {
//TODO signup fail, add signup fail message?
SimpleMessagePackage reply(Protocol::userSignupFail);
reply.setMessage("IT IS GROUP NAME");
reply.send(*socket);
} else {
if (currentUser.newUser(username, password) == USER_SIGNUP_SUCCESS) {
threadName = username;
Package reply(Protocol::userSignupSuccess);
// TODO: generate user id here
reply.send(*socket);
} else {
//TODO signup fail, add signup fail message?
SimpleMessagePackage reply(Protocol::userSignupFail);
reply.send(*socket);
}
}
} else if (currentPackage.getPackageType() == Protocol::userLogin) {
cout << "logging in..." << endl;
/* Login */
/* Receive packet contains username password */
memset(buff, 0, sizeof(buff));
socket->receive(buff, sizeof(buff));
UserInitPackage package = buff;
string username = package.getUserName();
string password = package.getUserPassword();
if(currentUser.login(username, password) == USER_LOGIN_SUCCESS) {
Package reply(Protocol::userLoginSuccess);
reply.send(*socket);
threadName = username;
currentUser.loadMessages();
checkNotification();
Utils::writeServerLog(username + " has logged in");
} else {
//send login failed
SimpleMessagePackage reply(Protocol::userLoginFail);
reply.setMessage("Login failed");
reply.send(*socket);
cout << USER_LOGIN_INVALID << endl;
}
} else if (currentPackage.getPackageType() == Protocol::messageSend) {
/* User sends message */
/* if user is present (threadlist) then send to its queue,
* else call the currentUser.dumpMessageTo(targetUser)
*/
memset(buff, 0, sizeof(buff));
socket->receive(buff, sizeof(buff));
MessageSendPackage package = buff;
string name = package.getReceiver();
time_t msgTime = package.getPackageTime();
string message = package.getMessage();
string msg = currentUser.getUserName() + " : " + message;
cout << msg << endl;
bool isGroupName = Group::isGroupExists(name);
if (isGroupName) {
Group* temp = Group::getGroup(name);
//.........这里部分代码省略.........