本文整理汇总了C++中PacketFunctions类的典型用法代码示例。如果您正苦于以下问题:C++ PacketFunctions类的具体用法?C++ PacketFunctions怎么用?C++ PacketFunctions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PacketFunctions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateRoom
void SMOnlineRoom::CreateRoom(PacketFunctions& Packet) {
bool origional_name = true;
SMOnlineRoom* tmp = NULL;
int type = Packet.Read1();
MString title = Packet.ReadNT();
MString sub = Packet.ReadNT();
MString passwd = Packet.ReadNT();
if (!title.empty())
{
if (title.size() > m_roomNameLength)
title = title.substr(0, m_roomNameLength);
for (unsigned int x = 0; (x < m_joinrooms.size()) && origional_name; ++x)
if (title == m_joinrooms[x]->m_title)
origional_name = false;
if (origional_name) {
if (type) {
tmp = new SMOnlineGameRoom(title, sub);
} else {
tmp = new SMOnlineRoom(title, sub);
}
if (tmp) {
LOG->Write("Created room");
if (!passwd.empty())
tmp->m_passwd = passwd;
SERVER->GetRooms().push_back(tmp);
JoinToRoom(tmp);
SendRoomList();
}
}
}
}
示例2: SMOnlineParse
void SMOnlineRoom::SMOnlineParse(PacketFunctions &Packet, int clientnum) {
int command = Packet.Read1();
switch (command) {
case 0:
//Login
break;
case 1:
//Change Room
{
int command = Packet.Read1();
MString title = Packet.ReadNT();
MString pw = Packet.ReadNT();
ChangeRoom(command, title, clientnum, pw);
}
break;
case 2:
//Create new room
if (m_allowgamerooms) {
CreateRoom(Packet);
ChangeRoom(1, m_joinrooms[m_joinrooms.size()-1]->GetTitle(), clientnum, "", true);
}
break;
case 3:
//Additional room info
GenAdditionalInfo(Packet.ReadNT(), clientnum);
break;
default:
LOG->Write(ssprintf("Invalid SMOnline command:%d", command));
break;
}
}
示例3: StyleUpdate
void GameClient::StyleUpdate(PacketFunctions& Packet)
{
int playernumber = 0;
Player[0].name = Player[1].name = "";
twoPlayers = Packet.Read1()-1;
for (int x = 0; x < twoPlayers+1; ++x)
{
playernumber = Packet.Read1();
Player[playernumber].name = Packet.ReadNT();
}
}
示例4: ParseData
void StepManiaLanServer::ParseData(PacketFunctions& Packet, const unsigned int clientNum)
{
int command = Packet.Read1();
switch (command)
{
case NSCPing:
// No Operation
SendValue(NSServerOffset + NSCPingR, clientNum);
break;
case NSCPingR:
// No Operation response
break;
case NSCHello:
// Hello
Hello(Packet, clientNum);
break;
case NSCGSR:
// Start Request
Client[clientNum]->StartRequest(Packet);
CheckReady(); //This is what ACTUALLY starts the games
break;
case NSCGON:
// GameOver
GameOver(Packet, clientNum);
break;
case NSCGSU:
// StatsUpdate
Client[clientNum]->UpdateStats(Packet);
if (!Client[clientNum]->lowerJudge)
CheckLowerJudge(clientNum);
break;
case NSCSU:
// Style Update
Client[clientNum]->StyleUpdate(Packet);
SendUserList();
break;
case NSCCM:
// Chat message
AnalizeChat(Packet, clientNum);
break;
case NSCRSG:
SelectSong(Packet, clientNum);
break;
case NSCSMS:
ScreenNetMusicSelectStatus(Packet, clientNum);
break;
case NSCUPOpts:
Client[clientNum]->Player[0].options = Packet.ReadNT();
Client[clientNum]->Player[1].options = Packet.ReadNT();
break;
default:
break;
}
}
示例5: ScreenNetMusicSelectStatus
void StepManiaLanServer::ScreenNetMusicSelectStatus(PacketFunctions& Packet, unsigned int clientNum)
{
CString message = "";
int EntExitCode = Packet.Read1();
message += Client[clientNum]->Player[0].name;
if (Client[clientNum]->twoPlayers)
message += "&";
message += Client[clientNum]->Player[1].name;
if (EntExitCode % 2 == 1)
Client[clientNum]->inNetMusicSelect = true;
else
Client[clientNum]->inNetMusicSelect = false;
switch (EntExitCode)
{
case 0:
message += " left the song selection.";
break;
case 1:
message += " entered the song selection.";
break;
case 2:
message += " went into options.";
break;
case 3:
message += " came back from options.";
break;
}
ServerChat(message);
}
示例6: GetData
int GameClient::GetData(PacketFunctions& Packet)
{
int length = -1;
Packet.ClearPacket();
length = clientSocket.ReadPack((char*)Packet.Data, NETMAXBUFFERSIZE);
return length;
}
示例7: Hello
void StepManiaLanServer::Hello(PacketFunctions& Packet, const unsigned int clientNum)
{
int ClientVersion = Packet.Read1();
CString build = Packet.ReadNT();
Client[clientNum]->SetClientVersion(ClientVersion, build);
Reply.ClearPacket();
Reply.Write1( NSCHello + NSServerOffset );
Reply.Write1(1);
Reply.WriteNT(servername);
SendNetPacket(clientNum, Reply);
if (ClientHost == -1)
ClientHost = clientNum;
}
示例8: AnalizeChat
void StepManiaLanServer::AnalizeChat(PacketFunctions &Packet, const unsigned int clientNum)
{
CString message = Packet.ReadNT();
if (message.at(0) == '/')
{
CString command = message.substr(1, message.find(" ")-1);
if ((command.compare("list") == 0)||(command.compare("have") == 0))
{
if (command.compare("list") == 0)
{
Reply.ClearPacket();
Reply.Write1(NSCCM + NSServerOffset);
Reply.WriteNT(ListPlayers());
SendNetPacket(clientNum, Reply);
}
else
{
message = "";
message += Client[clientNum]->Player[0].name;
if (Client[clientNum]->twoPlayers)
message += "&";
message += Client[clientNum]->Player[1].name;
message += " forces has song.";
Client[clientNum]->forceHas = true;
ServerChat(message);
}
}
else
{
if (clientNum == 0)
{
if (command.compare("force_start") == 0)
ForceStart();
if (command.compare("kick") == 0)
{
CString name = message.substr(message.find(" ")+1);
Kick(name);
}
if (command.compare("ban") == 0)
{
CString name = message.substr(message.find(" ")+1);
Ban(name);
}
}
else
{
Reply.ClearPacket();
Reply.Write1(NSCCM + NSServerOffset);
Reply.WriteNT("You do not have permission to use server commands.");
SendNetPacket(clientNum, Reply);
}
}
}
else
RelayChat(message, clientNum);
}
示例9: StartRequest
void GameClient::StartRequest(PacketFunctions& Packet)
{
int firstbyte = Packet.Read1();
int secondbyte = Packet.Read1();
int thirdbyte = Packet.Read1();
Player[0].feet = firstbyte/16;
Player[1].feet = firstbyte%16;
if ((Player[0].feet > 0)&&(Player[1].feet > 0))
twoPlayers = true;
Player[0].diff = secondbyte/16;
Player[1].diff = secondbyte%16;
startPosition = thirdbyte/16;
gameInfo.title = Packet.ReadNT();
gameInfo.subtitle = Packet.ReadNT();
gameInfo.artist = Packet.ReadNT();
gameInfo.course = Packet.ReadNT();
for (int x = 0; x < 2; ++x)
{
Player[x].score = 0;
Player[x].combo = 0;
Player[x].projgrade = 0;
Player[x].maxCombo = 0;
memset(Player[x].steps, 0, sizeof(int)*9);
}
GotStartRequest = true;
}
示例10: WriteRoomListPacket
void SMOnlineRoom::WriteRoomListPacket(PacketFunctions &Packet) {
unsigned int numRooms = m_joinrooms.size();
Packet.ClearPacket();
Packet.Write1(NSSMONL + NSServerOffset);
Packet.Write1(1); //Room command
Packet.Write1(1); //Type (List Rooms)
Packet.Write1(numRooms);
for (unsigned int x = 0; x < numRooms; ++x) {
if (m_joinrooms[x] != NULL) {
Packet.WriteNT(m_joinrooms[x]->GetTitle());
Packet.WriteNT(m_joinrooms[x]->GetDescription());
}
}
//state
for (unsigned int x = 0; x < numRooms; ++x) {
if (m_joinrooms[x] != NULL)
{
//TO MAKE CHARLES HAPPY IF PASSWORDED USE 1 (UNSUSED)
if (!m_joinrooms[x]->m_passwd.empty() && (m_joinrooms[x]->m_state == RS_OPEN))
Packet.Write1(RS_UNUSED);
else
Packet.Write1(m_joinrooms[x]->m_state);
}
}
//Flags
char flags;
for (unsigned int x = 0; x < numRooms; ++x) {
if (m_joinrooms[x] != NULL)
{
flags = 0;
//bit 1 passworded
if (!m_joinrooms[x]->m_passwd.empty())
flags += 1;
Packet.Write1(flags);
}
}
}
示例11: ScreenNetMusicSelectStatus
void StepManiaLanServer::ScreenNetMusicSelectStatus(PacketFunctions& Packet, unsigned int clientNum)
{
CString message = "";
int EntExitCode = Packet.Read1();
message += Client[clientNum]->Player[0].name;
if (Client[clientNum]->twoPlayers)
message += "&";
message += Client[clientNum]->Player[1].name;
if (EntExitCode % 2 == 1)
Client[clientNum]->inNetMusicSelect = true;
else
Client[clientNum]->inNetMusicSelect = false;
GameClient::LastNetScreen LastScreenInfo = GameClient::NS_NOWHERE;
switch (EntExitCode)
{
case 0:
message += " left the song selection.";
break;
case 1:
message += " entered the song selection.";
LastScreenInfo = GameClient::NS_SELECTSCREEN;
break;
case 2:
message += " exited options.";
break;
case 3:
message += " went into options.";
LastScreenInfo = GameClient::NS_OPTIONS;
break;
case 4:
//no need to mention exiting of options
break;
case 5:
message += " finished the game.";
LastScreenInfo = GameClient::NS_EVALUATION;
break;
}
ServerChat(message);
Client[clientNum]->NetScreenInfo = LastScreenInfo;
SendUserList ();
}
示例12: ParseData
void SMOnlineRoom::ParseData(PacketFunctions& Packet, int clientnum)
{
/* Try not to do any Packet Parsing here here because a lot of parsing
was done in the Client. Parsing again would be a waste.
Packet has been unaltered previous to this point.*/
int command = Packet.Read1();
switch (command)
{
case NSCPing:
// No Operation
// SendValue(NSServerOffset + NSCPingR, clientNum);
break;
case NSCPingR:
// No Operation response
break;
case NSCHello:
// Hello
break;
case NSCSU:
// Style Update
break;
case NSCCM:
// Chat message
AnalizeChat(clientnum, Packet);
break;
case NSCSMS:
//Room Status Change
SendRoomTitle(clientnum);
SendRoomList(clientnum);
break;
case NSSMONL:
SMOnlineParse(Packet, clientnum);
break;
default:
break;
}
}
示例13: UpdateStats
void GameClient::UpdateStats(PacketFunctions& Packet)
{
//Get the Stats from a packet
char firstbyte = Packet.Read1();
char secondbyte = Packet.Read1();
int pID = int(firstbyte/16); /* MSN */
Player[pID].currstep = int(firstbyte%16); /* LSN */
Player[pID].projgrade = int(secondbyte/16);
Player[pID].score = Packet.Read4();
Player[pID].combo = Packet.Read2();
if (Player[pID].combo > Player[pID].maxCombo)
Player[pID].maxCombo = Player[pID].combo;
Player[pID].health = Packet.Read2();
Player[pID].offset = ((double)abs(int(Packet.Read2())-32767)/2000);
Player[pID].steps[Player[pID].currstep]++;
}
示例14: SelectSong
void StepManiaLanServer::SelectSong(PacketFunctions& Packet, unsigned int clientNum)
{
int use = Packet.Read1();
CString message;
if (use == 2)
{
if (clientNum == 0)
{
SecondSameSelect = false;
CurrentSongInfo.title = Packet.ReadNT();
CurrentSongInfo.artist = Packet.ReadNT();
CurrentSongInfo.subtitle = Packet.ReadNT();
Reply.ClearPacket();
Reply.Write1(NSCRSG + NSServerOffset);
Reply.Write1(1);
Reply.WriteNT(CurrentSongInfo.title);
Reply.WriteNT(CurrentSongInfo.artist);
Reply.WriteNT(CurrentSongInfo.subtitle);
//Only send data to clients currently in ScreenNetMusicSelect
for (unsigned int x = 0; x < Client.size(); ++x)
if (Client[x]->inNetMusicSelect)
SendNetPacket(x, Reply);
//The following code forces the host to select the same song twice in order to play it.
if ((strcmp(CurrentSongInfo.title, LastSongInfo.title) == 0) &&
(strcmp(CurrentSongInfo.artist, LastSongInfo.artist) == 0) &&
(strcmp(CurrentSongInfo.subtitle, LastSongInfo.subtitle) == 0))
SecondSameSelect = true;
if (!SecondSameSelect)
{
LastSongInfo.title = CurrentSongInfo.title;
LastSongInfo.artist = CurrentSongInfo.artist;
LastSongInfo.subtitle = CurrentSongInfo.subtitle;
message = "Play \"";
message += CurrentSongInfo.title + " " + CurrentSongInfo.subtitle;
message += "\"?";
ServerChat(message);
}
}
else
{
message = servername;
message += ": You do not have permission to pick a song.";
Reply.ClearPacket();
Reply.Write1(NSCCM + NSServerOffset);
Reply.WriteNT(message);
SendNetPacket(clientNum, Reply);
}
}
if (use == 1)
{
//If user dosn't have song
Client[clientNum]->hasSong = false;
message = Client[clientNum]->Player[0].name;
if (Client[clientNum]->twoPlayers)
{
message += "&";
message += Client[clientNum]->Player[1].name;
}
message += " lacks song \"";
message += CurrentSongInfo.title;
message += "\"";
ServerChat(message);
}
//If client has song
if (use == 0)
Client[clientNum]->hasSong = true;
//Only play if everyone has the same song and the host has select the same song twice.
if ( CheckHasSongState() && SecondSameSelect && (clientNum == 0) )
{
ClientsSongSelectStart();
//Reset last song in case host picks same song again (otherwise dual select is bypassed)
ResetLastSongInfo();
}
}
示例15: StatsProjgradeColumn
void StepManiaLanServer::StatsProjgradeColumn(PacketFunctions& data, vector<LanPlayer*> &playersPtr)
{
for(unsigned int x = 0; x < playersPtr.size(); ++x )
data.Write1( (uint8_t) playersPtr[x]->projgrade );
}