bool G::CostMoney(int moneyCost){ if (moneyCost>getMoney()) { return false; } setMoney(getMoney()-moneyCost); return true; }
local void showMoneyCommand(const char *command, const char *params, Player *p, const Target *target) { if (target->type == T_PLAYER) //private command { Player *t = target->u.p; if (database->isLoaded(p)) { if (strstr(params, "-e")) //wants exp too { chat->SendMessage(t, "Player %s has $%i in their account and %i experience.", p->name, getMoney(p), getExp(p)); chat->SendMessage(p, "Sent money and exp status to %s", t->name); } else //no exp { chat->SendMessage(t, "Player %s has $%i in their account.", p->name, getMoney(p)); chat->SendMessage(p, "Sent money status to %s", t->name); } } else { chat->SendMessage(p, "You have no data loaded."); } } else //not private { chat->SendMessage(p, "You must target a player."); } }
//客户端界面 void mainPage(){ while(1){ printf(" 欢迎使用迷你ATM机\n"); printf("---------------------\n"); printf("[1] 开户"); printf(" [2] 销户\n"); printf("[3] 存钱"); printf(" [4] 取钱\n"); printf("[5] 查询"); printf(" [6] 转账\n"); printf("[0] 退出\n"); printf("---------------------\n"); printf("请选择:\n"); int num = 0; scanf("%d",&num); switch(num){ case 1:createUser();break; case 2:destroyUser();break; case 3:saveMoney();break; case 4:getMoney();break; case 5:checkMoney();break; case 6:moveMoney();break; case 0:printf("谢谢使用,再见!\n");return ; default:printf("输入错误\n"); } } }
local void moneyCommand(const char *command, const char *params, Player *p, const Target *target) { if (target->type == T_PLAYER) //private command { Player *t = target->u.p; if (database->isLoaded(t)) { if (strstr(params, "-d")) //wants details { int i; int total = 0; chat->SendMessage(p, "Player %s: money: %i, exp: %i", t->name, getMoney(t), getExp(t)); for (i = 0; i < MONEY_TYPE_COUNT; i++) { chat->SendMessage(p, "%s money: $%i", moneyTypeNames[i], getMoneyType(t, i)); total += getMoneyType(t, i); } chat->SendMessage(p, "Difference: $%i", getMoney(t) - total); } else //no details { chat->SendMessage(p, "Player %s has $%i in their account, and %i experience.", t->name, getMoney(t), getExp(t)); } } else { chat->SendMessage(p, "Player %s has no data loaded.", t->name); } } else //not private, assume public { if (database->isLoaded(p)) { chat->SendMessage(p, "You have $%i in your account and %i experience.", getMoney(p), getExp(p)); } else { chat->SendMessage(p, "You have no data loaded."); } } }
void G::setMoney(int money) { if (money == getMoney()) { return; } setIntForKey("money", money+MONEY_OFFSET); UserDefault::getInstance()->flush(); Director::getInstance()->getEventDispatcher()->dispatchCustomEvent(EVENT_MONEY_UPDATE); }
/** 选择相应的操作,按6退出系统 */ void operation() { int choice; // 操作选择 do { printf("**********欢迎来到坑钱银行*********\n"); printf("选择以下操作:1、开户 2、存款 3、取款 4、转账 5、查询 6、退出系统\n"); scanf("%d", &choice); switch(choice) { case 1: openAccount(); break; case 2: save(); break; case 3: getMoney(); break; case 4: transfer(); break; case 5: query(); break; default:break; } } while(choice != 6); }
void Boss_Efreeti::death() { if(GameManager::getInstance()->monsterVector.contains(this)){ GameManager::getInstance()->monsterVector.eraseObject(this); } if(getState()!=stateDeath){ SoundManager::playEfreetiDeath(); unschedule(schedule_selector(Boss_Efreeti::skill)); setState(stateDeath); hpBgSprite->setVisible(false); baseSprite->stopAllActions(); unscheduleUpdate(); GameManager::getInstance()->MONEY = GameManager::getInstance()->MONEY + getMoney(); baseSprite->runAction(Sequence::create( Animate::create(AnimationCache::getInstance()->getAnimation(getName()+"death")), CallFuncN::create(CC_CALLBACK_0(BaseMonster::setVisible, this,false)) ,NULL)); } }
local void setMoney(Player *p, int amount, MoneyType type) { giveMoney(p, amount - getMoney(p), type); }
local void giveCommand(const char *command, const char *params, Player *p, const Target *target) { char *next; char *message; int amount = strtol(params, &next, 0); if (next == params) { chat->SendMessage(p, "Give: bad amount."); return; } while (*next == ',' || *next == ' ') next++; //remove whitespace before the message message = next; if (message[0] == '\0') { message = NULL; } if (target->type == T_PLAYER) //private command { Player *t = target->u.p; if (database->isLoaded(p)) { if (database->isLoaded(t)) { /* cfghelp: Hyperspace:MinMoney, global, int, def: 1000, mod: hscore_money * The amount of money that must be left behind when using ?give. */ int minMoney = cfg->GetInt(GLOBAL, "hyperspace", "minmoney", 1000); /* cfghelp: Hyperspace:MinGive, global, int, def: 1, mod: hscore_money * The smallest amount that can be transferred using ?give. */ int minGive = cfg->GetInt(GLOBAL, "hyperspace", "mingive", 1); /* cfghelp: Hyperspace:MaxGive, global, int, def: 100000000, mod: hscore_money * The largest amount that can be transferred using ?give. */ int maxGive = cfg->GetInt(GLOBAL, "hyperspace", "maxgive", 100000000); if (getMoney(p) - amount >= minMoney) { if (amount <= maxGive) { if (amount >= minGive) { giveMoney(t, amount, MONEY_TYPE_GIVE); giveMoney(p, -amount, MONEY_TYPE_GIVE); if (message == NULL) { chat->SendMessage(t, "Player %s gave you $%i.", p->name, amount); } else { chat->SendMessage(t, "Player %s gave you $%i. Message: \"%s\"", p->name, amount, message); } chat->SendMessage(p, "You gave %s $%i.", t->name, amount); mysql->Query(NULL, NULL, 0, "INSERT INTO hs_transactions (srcplayer, tgtplayer, action, amount) VALUES(#,#,#,#)", database->getPerPlayerData(p)->id, database->getPerPlayerData(t)->id, MONEY_TYPE_GIVE, amount); } else { chat->SendMessage(p, "You cannot give that little. The minimum is %i.", minGive); } } else { chat->SendMessage(p, "You cannot give that much. The maximium is %i.", maxGive); } } else { chat->SendMessage(p, "You must leave at least %i in your own account.", minMoney); } } else { chat->SendMessage(p, "Player %s has no data loaded.", t->name); } } else { chat->SendMessage(p, "You have no data loaded."); } } else //not private { chat->SendMessage(p, "You must target a player."); } }
local void setMoneyCommand(const char *command, const char *params, Player *p, const Target *target) { int force = 0; int quiet = 0; char *next; char *message; int amount; while (params != NULL) //get the flags { if (strncmp(params, "-f", 2) == 0) { force = 1; } else if (strncmp(params, "-q", 2) == 0) { quiet = 1; } else { break; } params = strchr(params, ' '); if (params) //check so that params can still == NULL { params++; //we want *after* the space } } if (params == NULL) { chat->SendMessage(p, "Grantexp: invalid usage."); return; } amount = strtol(params, &next, 0); if (next == params) { chat->SendMessage(p, "Grantexp: bad amount."); return; } while (*next == ' ') next++; //remove whitespace before the message message = next; if (message[0] == '\0') { message = NULL; } //all the parsing is now complete if (target->type == T_PLAYER) //private command { Player *t = target->u.p; if (!force) { if (database->isLoaded(t)) { int oldAmount = getMoney(t); mysql->Query(NULL, NULL, 0, "INSERT INTO hs_transactions (srcplayer, tgtplayer, action, amount) VALUES(#,#,#,#)", database->getPerPlayerData(p)->id, database->getPerPlayerData(t)->id, MONEY_TYPE_GRANT, amount - oldAmount); setMoney(t, amount, MONEY_TYPE_GRANT); if (quiet) { chat->SendMessage(p, "Quietly set player %s's money to $%i (from %i).", t->name, amount, oldAmount); } else { if (message == NULL) { chat->SendMessage(t, "Your money was set to $%i.", amount); } else { chat->SendMessage(t, "Your money was set to $%i %s", amount, message); } chat->SendMessage(p, "Set player %s's money to $%i (from %i).", t->name, amount, oldAmount); } } else { chat->SendMessage(p, "Player %s has no data loaded.", t->name); } } else { chat->SendMessage(p, "Whoa there, bud. The -f is only for arena and freq messages."); } } else //not private { if (force) { LinkedList set = LL_INITIALIZER; Link *link; int count; pd->TargetToSet(target, &set); for (link = LLGetHead(&set); link; link = link->next) { Player *t = link->data; if (database->isLoaded(t)) { mysql->Query(NULL, NULL, 0, "INSERT INTO hs_transactions (srcplayer, tgtplayer, action, amount) VALUES(#,#,#,#)", database->getPerPlayerData(p)->id, database->getPerPlayerData(t)->id, MONEY_TYPE_GRANT, amount - getMoney(t)); setMoney(t, amount, MONEY_TYPE_GRANT); if (!quiet) { if (message == NULL) { chat->SendMessage(t, "Your money was set to $%i.", amount); } else { chat->SendMessage(t, "Your money was set to $%i %s", amount, message); } } } else { chat->SendMessage(p, "Player %s has no data loaded.", t->name); } } count = LLCount(&set); LLEmpty(&set); chat->SendMessage(p, "You set %i players money to $%i.", count, amount); } else { chat->SendMessage(p, "For typo safety, the -f must be specified for arena and freq targets."); } } }
void Player::muchCheat(){ setMoney(getMoney() + 10000); }
void *handle(void *arg) { char recvbuff[256]; char sendbuff[256]; int n; memset(recvbuff, '\0', 256); memset(sendbuff, '\0', 256); int connfd = *(int *)arg; struct Account acc; struct Account p; while(1) { n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; printf("%s\n",recvbuff); if(strcmp(recvbuff,"1")==0) { memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.name,recvbuff); printf("%s\n",acc.name); memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.password,recvbuff); printf("%s\n",acc.password); memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.money,recvbuff); printf("%s\n",acc.money); createUser(acc); strcpy(sendbuff,"creat a new user success"); write(connfd,sendbuff,sizeof(sendbuff)); } if(strcmp(recvbuff,"2")==0) { memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.name,recvbuff); printf("%s\n",acc.name); memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.password,recvbuff); printf("%s\n",acc.password); destoryUser(acc); memset(sendbuff, '\0', 256); strcpy(sendbuff,"destroyUser success"); write(connfd,sendbuff,sizeof(sendbuff)); } if(strcmp(recvbuff,"3")==0) { memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.name,recvbuff); printf("%s\n",acc.name); memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.password,recvbuff); printf("%s\n",acc.password); memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.money,recvbuff); printf("%s\n",acc.money); p=saveMoney(acc); if(strcmp(p.password,acc.password)==0) { memset(sendbuff, '\0', 256); strcpy(sendbuff,p.money); write(connfd,sendbuff,sizeof(sendbuff)); } else { memset(sendbuff, '\0', 256); strcpy(sendbuff,"password wrong"); write(connfd,sendbuff,sizeof(sendbuff)); } } if(strcmp(recvbuff,"4")==0) { memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.name,recvbuff); printf("%s\n",acc.name); memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.password,recvbuff); printf("%s\n",acc.password); memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.money,recvbuff); printf("%s\n",acc.money); p=getMoney(acc); if(strcmp(p.password,acc.password)==0) { memset(sendbuff, '\0', 256); strcpy(sendbuff,p.money); write(connfd,sendbuff,sizeof(sendbuff)); } else { memset(sendbuff, '\0', 256); strcpy(sendbuff,"password wrong"); write(connfd,sendbuff,sizeof(sendbuff)); } } if(strcmp(recvbuff,"5")==0) { memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.name,recvbuff); printf("%s\n",acc.name); memset(recvbuff, '\0', 256); n=read(connfd,recvbuff,sizeof(recvbuff)); recvbuff[n]=0; strcpy(acc.password,recvbuff); printf("%s\n",acc.password); p=checkMoney(acc); if(strcmp(p.password,acc.password)==0) { memset(sendbuff, '\0', 256); strcpy(sendbuff,p.money); write(connfd,sendbuff,sizeof(sendbuff)); } else { memset(sendbuff, '\0', 256); strcpy(sendbuff,"password wrong"); write(connfd,sendbuff,sizeof(sendbuff)); } } } }
int main() { int msgid1 = msgget(key1,0); if(msgid1 == -1) { perror("获取消息队列一失败"); printf("服务启动失败\n"); exit(-1); } int msgid2 = msgget(key2,0); if(msgid2 == -1) { perror("获取消息队列二失败"); printf("服务启动失败\n"); exit(-1); } //开始接受消息 while(1) { struct Msg msg; struct Account accMove,accResult; if(msgrcv(msgid1,&msg,sizeof(msg.acc),0,0) <= 0) { continue; } if(msg.mtype == M_OPEN) { int id = generator_id(); accMove = msg.acc; accMove.id = id; if(createUser(accMove) == -1) { printf("开户失败\n"); msg.mtype = M_FAILED; } else { printf("开户成功\n"); msg.mtype = M_SUCESS; } msgsnd(msgid2,&msg,sizeof(msg.acc),0); } else if(msg.mtype == M_DESTROY) { if(destoryUser(msg.acc) == -1) { printf("销户失败\n"); msg.mtype = M_FAILED; } else { printf("销户成功\n"); msg.mtype = M_SUCESS; } msgsnd(msgid2,&msg,sizeof(msg.acc),0); } else if(msg.mtype == M_SAVE) { if(saveMoney(msg.acc, &accResult) == -1) { printf("存钱失败\n"); msg.mtype = M_FAILED; } else { printf("存钱成功\n"); msg.mtype = M_SUCESS; } //发送是否存钱成功的标志 msg.acc.balance = accResult.balance; msgsnd(msgid2,&msg,sizeof(msg.acc),0); } else if(msg.mtype == M_TAKE) { if(getMoney(msg.acc,&accResult) == -1) { printf("取钱失败\n"); msg.mtype = M_FAILED; } else { printf("取钱成功\n"); msg.mtype = M_SUCESS; } //将服务器处理的结果发送给客户端 msg.acc.balance = accResult.balance; msgsnd(msgid2,&msg,sizeof(msg.acc),0); } else if(msg.mtype == M_QUERY) { if(checkMoney(msg.acc,&accResult) == -1) { printf("查询失败\n"); msg.mtype = M_FAILED; } else { printf("查询成功\n"); msg.mtype = M_SUCESS; } //发送查询出的余额 msg.acc.balance = accResult.balance; msgsnd(msgid2,&msg,sizeof(msg.acc),0); } else if(msg.mtype == M_TRANSF) { //定义一个消息结构体,来接受转入的帐号 struct Msg msgTemp; msgrcv(msgid1,&msgTemp,sizeof(msgTemp.acc),0,0); if(moveMoney(msg.acc,msgTemp.acc,&accResult) == -1) { printf("转入失败\n"); msg.mtype = M_FAILED; } else { printf("转入成功\n"); msg.mtype = M_SUCESS; } msg.acc.balance = accResult.balance; printf("转帐之后的结果是:%lf\n",msg.acc.balance); //发送处理结果到客户端 msgsnd(msgid2,&msg,sizeof(msg.acc),0); } } return 0; }
void Mechanoid::addMoney(float m) { setMoney(getMoney() + m); }
void G::AddMoney(int moneyAdd){ setMoney(getMoney()+moneyAdd); }