void BatteryCharger::Load(char *line) { int bat; sscanf (line," <BATTERYCHARGER> %s %i", name, &bat); Charge(bat); }
void CSimpleBattery::TimeElapse(double time, double timeElapsed) { if( _portCurrent < 0 ) { _consumption += Discharge(timeElapsed,-_portCurrent); } else if( _portCurrent > 0 ) { _consumption -= Charge(timeElapsed,_portCurrent); } }
void HospitalizationManagement::initUI() { Registry(); Pay(); Charge(); Discharge(); InternalPayment(); Dailyreport(); Statistics(); }
void FORTE_iCreateBattery::executeEvent(int pa_nEIID){ switch (pa_nEIID){ case scm_nEventREQID: create_battery_charge(); Charging() = static_cast<TForteInt16>(gc_charge_state); //get_create_charging_state(LAG()); Voltage() = static_cast<TForteInt16>(gc_batt_voltage); Current() = static_cast<TForteInt16>(gc_current_flow); Temperature() = static_cast<TForteInt16>(gc_batt_temp); Charge() = static_cast<TForteInt16>(gc_batt_charge); Capacity() = static_cast<TForteInt16>(gc_batt_capacity); sendOutputEvent(scm_nEventCNFID); break; } }
npc_lightning_elementalAI(Creature *c) : ScriptedAI(c) { Charge(); Casted = false; }
int AuthClientUser::ClientProcessThread(SingleThread * self) { CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); int timeout = SOCKET_TIMEOUT; setsockopt(m_ClientSocket, SOL_SOCKET, SO_RCVTIMEO,(char*)&timeout, sizeof(timeout)); vector<BYTE> output; //1. Auth if(!this->SocketReadBuff(sizeof(tagCClientAuth), &output)) { SocketReadError("tagCClientAuth SocketReadBuff Error"); return -1; } tagCClientAuth *clietAuth = (tagCClientAuth *)&output[0]; clietAuth->UserName[sizeof(clietAuth->UserName)-1] = '\0'; m_UserName = clietAuth->UserName; m_UserName = m_UserName.LowerCase(); m_UserName = m_UserName.Trim(); string input_username = clietAuth->UserName; SendLogMessage(FormatStr(GBText("用户[%s]开始验证..."), m_UserName)); m_Build = clietAuth->Build; BigNumber A, s, B, K, M2; A.SetBinary(clietAuth->A, sizeof(clietAuth->A)); m_IsChargeProcess = clietAuth->IsChargeProcess; if(!m_SRP6Server.CalcKey(input_username, input_username, A, &s, &B, &K)) { SendLogMessage("错误(1)"); SocketReadError("CalcKey Error"); return -1; } tagSClientAuth sendAuth; memcpy(sendAuth.s, s.AsByteArray(), sizeof(sendAuth.s)); memcpy(sendAuth.B, B.AsByteArray(), sizeof(sendAuth.B)); if(!this->SendAuthMessage((BYTE *)&sendAuth, sizeof(sendAuth))) { SocketReadError("tagSClientAuth SocketSend Error"); return -1; } //2. Auth Check if(!this->SocketReadBuff(sizeof(tagCAuthCheck), &output)) { SocketReadError("tagCAuthCheck SocketReadBuff Error"); return -1; } tagCAuthCheck *clientAuthCheck = (tagCAuthCheck *)&output[0]; if(!m_SRP6Server.CheckClientAuth(input_username, clientAuthCheck->M, &M2)) { SendLogMessage("错误(2)"); SocketReadError("Auth Check Error"); return -1; } tagSAuthCheck sendAuthCheck; memcpy(sendAuthCheck.M2, M2.AsByteArray(), sizeof(sendAuthCheck.M2)); if(!this->SendAuthMessage((BYTE *)&sendAuthCheck, sizeof(sendAuthCheck))) { SocketReadError("tagSAuthCheck SocketSend Error"); return -1; } m_AuthCrypt.Init(&K, WOWWGUserServerEncryptionKey, WOWWGUserServerDecryptionKey); vector<String> outputMsg; if(!CheckUserCanLogin(&outputMsg)) { for(DWORD i=0; i<outputMsg.size(); i++) { SendLogMessage(outputMsg[i]); } SocketReadError(FormatStr("[RefuseLogin]:%s", m_RefuseLoginReason)); return -1; } for(DWORD i=0; i<outputMsg.size(); i++) { SendLogMessage(outputMsg[i]); } // SendLogMessage(FormatStr(GBText("用户[%s]验证成功!"), m_UserName)); TDateTime expTime; if(m_IsChargeProcess) { //充值 BYTE len = 0; if(!this->SocketReadBYTE(&len)) { SendLogMessage("错误(17)"); SocketReadError("Charge CardNo Read Len Error"); return -1; } if(!this->SocketReadBuff(len, &output)) { SendLogMessage("错误(14)"); SocketReadError("Charge CardNo Read Error"); return -1; } AnsiString cardNo = AnsiString((char *)&output[0], len); cardNo = cardNo.Trim(); cardNo = cardNo.UpperCase(); outputMsg.clear(); if(!Charge(m_ADOQuery, m_UserName, cardNo, &outputMsg)) { for(DWORD i=0; i<outputMsg.size(); i++) { SendLogMessage(outputMsg[i]); } SocketReadError("Charge Fail!"); return -1; } for(DWORD i=0; i<outputMsg.size(); i++) { SendLogMessage(outputMsg[i]); } outputMsg.clear(); if(!GetExpireTime(m_ADOQuery, m_UserName, &outputMsg, &expTime)) { for(DWORD i=0; i<outputMsg.size(); i++) { SendLogMessage(outputMsg[i]); } SocketReadError("Charge GetExpireTime Fail!"); return -1; } for(DWORD i=0; i<outputMsg.size(); i++) { SendLogMessage(outputMsg[i]); } SendLogMessage(GBText("充值成功!")); } else { //验证 tagWOWAddrInfo addrInfo; if(!FindAddrInfo(m_Build, &addrInfo)) { SendLogMessage("错误(3)"); GetLog()->Error("No Build Msg. Build = %d", m_Build); SocketReadError("We Don't Have This Build!"); return -1; } outputMsg.clear(); if(!GetExpireTime(m_ADOQuery, m_UserName, &outputMsg, &expTime)) { for(DWORD i=0; i<outputMsg.size(); i++) { SendLogMessage(outputMsg[i]); } SocketReadError("GetExpireTime Fail!"); return -1; } for(DWORD i=0; i<outputMsg.size(); i++) { SendLogMessage(outputMsg[i]); } tagClientAddrInfo info; info.Address = addrInfo.Addr; info.Offset = addrInfo.Offset; info.ExpireTime = expTime; if(!this->SendAuthMessage((BYTE *)&info, sizeof(tagClientAddrInfo))) { SocketReadError("tagClientAddrInfo SocketSend Error"); return -1; } m_ADOQuery->SQL->Text = FormatStr("SELECT * FROM wow_msg where msg_key = '%s'", L"login"); if(OpenSQL(m_ADOQuery)) { if(m_ADOQuery->RecordCount) { m_ADOQuery->First(); String text = m_ADOQuery->FieldByName("msg")->AsString; SendLogMessage(text); } } SendLogMessage(GBText("验证成功!")); } SendLogMessage(GBText(FormatStr("你的帐号[%s]到期时间为:%s", m_UserName, DateTimeToStr(expTime)))); OnLoginSuccess(); Sleep(1000); this->SetIsClosed(1); return -1; }
bool AuthClientUser::OnUserFirstLogin(vector<String> *outputMsg) { //1. 取一张免费卡 vector<tagCardInfo> freeCardList; for(int i=0; i<GetAuthServerListener()->GetCardInfoCount(); i++) { tagCardInfo *info = GetAuthServerListener()->GetCardInfoByIndex(i); if(!info) continue; if(info->CardMoney != 0) continue; freeCardList.push_back(*info); } sort(freeCardList.begin(), freeCardList.end(),greater<tagCardInfo>()); String cardType, cardNo; for(DWORD i=0; i<freeCardList.size(); i++) { if(GetCard(m_ADOQuery, freeCardList[i].CardType, &cardNo, outputMsg)) { cardType = freeCardList[i].CardType; break; } } if(cardNo == "") { if(m_IsChargeProcess == 0) { //免费卡已经发放完毕 outputMsg->push_back(GBText("免费卡已经发放完毕, 请注册!")); SendRegMessage(); return false; } else { outputMsg->push_back(GBText("对不起, 免费卡已经发放完毕!")); } } //2. 创建用户 String nowStr = DateTimeToStr(Now()); m_ADOQuery->SQL->Text = FormatStr("INSERT wow_user (" "accid, last_login_time, login_count, start_time, end_time, " "total_time, money_total_time, money, login_ip, create_time, " "create_ip) VALUES(" "'%s', '%s', %d, '%s', '%s'," "%d, %d, %d, '%s', '%s'," "'%s'" ")", m_UserName, nowStr, 0, nowStr, nowStr, 0, 0, 0, m_ClientIP, nowStr, m_ClientIP ); if(!ExecSQL(m_ADOQuery)) { outputMsg->push_back(GBText("错误(9)")); return false; } m_ADOQuery->SQL->Text = FormatStr("SELECT * FROM wow_msg where msg_key = '%s'", L"first_login"); if(!OpenSQL(m_ADOQuery)) { outputMsg->push_back(GBText("错误(10)")); return false; } if(m_ADOQuery->RecordCount) { m_ADOQuery->First(); String text = m_ADOQuery->FieldByName("msg")->AsString; outputMsg->push_back(text); } //3. 充值 if(cardNo != "") { if(!Charge(m_ADOQuery, m_UserName, cardNo, outputMsg)) { return false; } } return true; }
/* The consequenses of giving commands through the app are happening here. Several statusses are used to determine the possibl commands that can be given. */ task main(){ while (true){ /* Standby The robot stays still untill it is told to either follow the line or go over to manual mode. FIRE: Status goes to active. A: Status goes to manual. */ while (status == "standby"){ CheckString(); if( s == "FIRE"){ startTask(Follow); status = "active"; } if (s == "A"){ status = "manual"; } } /* Active The robot is following the line untill it is told to go standby or if it sees an object. UP: Command to make the robot go straight on the next crossing. LEFT: Command to make the robot go left on the next crossing. RIGHT:Command to make the robot go right on the next crossing. FIRE: Command to make the robot wait for a command on the next crossing. C: Status goes to standby. */ while (status == "active"){ CheckString(); if( s == "C") { status = "standby"; speed = 0; stopTask(Follow); StopSound(); Straight(speed); } if (s == "RIGHT"){ command = "right"; } if (s == "LEFT"){ command = "left"; } if (s == "UP"){ command = "straight"; } } /* Engage The robot has seen an object and is waiting for a command that decides if it will charge or evade said object. FIRE: Robot evades the object. (Evasion handled in task Follow) B: The robot Charges. C: Status goes to standby. */ while (status == "engage"){ CheckString(); if(s == "FIRE"){ } if(s == "B"){ stopTask(Follow); StopSound(); Charge(); s = ""; status = "standby"; } if (s == "C"){ CheckString(); status = "standby"; speed = 0; stopTask(Follow); stopTask(AvoidObject); StopSound(); Straight(speed); } if (SensorValue[S1] == 1){ status = "standby"; speed = 0; stopTask(Follow); stopTask(AvoidObject); StopSound(); Straight(speed); } } /* Manual The robot can be manually controlled untill it is told to go back to standby. UP: The robot moves forward. RIGHT:Turn right. LEFT: Turn left. DOWN: The robot moves backward. FIRE: Brake. B: The robot charges. C: Status goes to standby. */ while(status == "manual"){ CheckString(); Straight(0); while (s == "UP"){ startTask(Sound); CheckString(); Straight(max_Speed); } while (s == "DOWN"){ startTask(Sound); CheckString(); Straight((max_Speed/2)*-1); } while (s == "LEFT"){ CheckString(); startTask(Sound); motor[motorB]= 0; motor[motorC]= max_Speed/2; } while (s == "RIGHT"){ startTask(Sound); CheckString(); motor[motorC]= 0; motor[motorB]= max_Speed/2; } if (s == "C"){ CheckString(); status = "standby"; speed = 0; stopTask(Follow); StopSound(); Straight(speed); } while (s == "FIRE"){ StopSound(); CheckString(); motor[motorB]= 0; motor[motorC]= 0; } if (s == "B"){ StopSound(); Charge(); } } wait1Msec(1); } }
/* ---------------------------------- Server side IO implementation ---- */ PUBLIC void IOThread(disk_t *disk) { stream_t *stream; QoSEntry_clp qosentry = disk->qosentry; Time_T pre,post; IO_clp io; IO_Rec recs[2]; uint32_t nrecs; word_t value; uint32_t offset; Time_ns cost; uint32_t notify; USD_Extent ext; FileIO_Request copyreq; FileIO_Request *req; while (True) { TRC(printf(__FUNCTION__": about to Rendezvous...\n")); io = IOEntry$Rendezvous((IOEntry_clp)qosentry, FOREVER); /* ** Account the time we're about to spend processing this packet ** to the QosEntry: for now, we just are sych. and so can ** actually count the amount of time. XXX no overhead accounted. */ pre = NOW(); TRC(printf(__FUNCTION__": back from Rdzvs, io at %p\n", io)); /* Find out whose IO it is */ stream = (stream_t *)IO_HANDLE(io); offset = stream->usd->partition->p_offset; TRC(printf("(It's stream %d)\n",stream->sid)); /* XXX SMH: nasty hardwired request/buffer IO_Rec pair */ if (IO$GetPkt(io, 2, recs, 0, &nrecs, &value)) { FTRC("got packet.\n"); req = (FileIO_Request *)recs[0].base; copyreq = *req; IOTRC(printf("req=%p\n",req)); IOTRC(printf("%qx:(%qd,%d)\n", stream->sid, copyreq.blockno, copyreq.nblocks)); /* Translate the addresses in the request */ if(!USDCallback$Translate(stream->usd->callbacks, stream->sid, stream->cid, ©req, &ext, ¬ify)) { TRC(printf("denied %qx:(%qd,%x)\n", stream->sid, copyreq.blockno, copyreq.nblocks)); req->rc = FileIO_RC_DENIED; goto denied; } /* Actually do the transaction */ switch(copyreq.op) { case FileIO_Op_Read: FTRC("trying to read.\n"); MU_LOCK(&disk->mu); if (BlockDev$Read((BlockDev_clp)disk->device, ext.base + offset, ext.len, recs[1].base)) { req->rc = FileIO_RC_OK; FTRC("done.\n"); } else { req->rc = FileIO_RC_FAILURE; FTRC("failure trying to read.\n"); } MU_RELEASE(&disk->mu); break; case FileIO_Op_Write: FTRC("trying to write.\n"); MU_LOCK(&disk->mu); if (BlockDev$Write((BlockDev_clp)disk->device, ext.base + offset, ext.len, recs[1].base)) { req->rc = FileIO_RC_OK; FTRC("done.\n"); } else { req->rc = FileIO_RC_FAILURE; FTRC("failure trying to write.\n"); } MU_RELEASE(&disk->mu); break; case FileIO_Op_Sync: FTRC("trying to sync.\n"); printf(__FUNCTION__": FileIO_Op_Sync unimplemented.\n"); FTRC("done.\n"); break; default: printf(__FUNCTION__": bad FileIO_Op %x\n", copyreq.op); ntsc_dbgstop(); } USDCallback$Notify(stream->usd->callbacks, stream->sid, stream->cid, ©req, &ext, notify, recs[1].base); denied: post = NOW(); cost = post - pre; QoSEntry$Charge(qosentry, io, cost); /* Return the IO_Rec vector */ TRC(printf("USD$IOThread: returning IOs.\n")); IO$PutPkt(io, nrecs, &recs[0], cost, 0); } } /* while true */ printf("USD$IOThread: BAD NEWS. Exiting (?)\n"); }
void Path::AddChock( Charges &charges, Vec2i point, Vec2i dir, int type ) { AddChock( charges, Charge( point, dir, type ) ); }