unsigned int CNetServer::RPC(RPCIdentifier rpcId, CBitStream * pBitStream, ePacketPriority priority, ePacketReliability reliability, EntityId playerId, bool bBroadcast, char cOrderingChannel) { if(playerId != INVALID_ENTITY_ID && !IsPlayerConnected(playerId)) return 0; CBitStream bitStream; bitStream.Write((PacketId)PACKET_RPC); bitStream.Write(rpcId); if(pBitStream) bitStream.Write((char *)pBitStream->GetData(), pBitStream->GetNumberOfBytesUsed()); return m_pRakPeer->Send((char *)bitStream.GetData(), bitStream.GetNumberOfBytesUsed(), (PacketPriority)priority, (PacketReliability)reliability, cOrderingChannel, (playerId == INVALID_ENTITY_ID) ? RakNet::UNASSIGNED_SYSTEM_ADDRESS : m_pRakPeer->GetSystemAddressFromIndex(playerId), bBroadcast); }
static void SAMPGDK_CALL MoneyGrubScoreUpdate(int timerid, void *param) { int CashScore; char name[MAX_PLAYER_NAME]; char string[128]; for(int i=0; i<MAX_PLAYERS; i++) { if (IsPlayerConnected(i)) { GetPlayerName(i, name, MAX_PLAYER_NAME); CashScore = GetPlayerMoney(i); SetPlayerScore(i, CashScore); if (CashScore > CashScoreOld) { CashScoreOld = CashScore; sprintf(string, "$$$ %s is now in the lead $$$", name); SendClientMessageToAll(COLOR_YELLOW, string); } } } }
PacketId CNetServer::ProcessPacket(RakNet::SystemAddress systemAddress, PacketId packetId, unsigned char * ucData, int iLength) { // Get the player id EntityId playerId = (EntityId)systemAddress.systemIndex; // Is the player not fully connected yet? if(!IsPlayerConnected(playerId)) { // Is this a disconnection or connection lost packet? if(packetId == ID_DISCONNECTION_NOTIFICATION || packetId == ID_CONNECTION_LOST) { // Ignore it return INVALID_PACKET_ID; } // Is this not a pre-connect packet? if(packetId != ID_NEW_INCOMING_CONNECTION && packetId != ID_USER_PACKET_ENUM) { // Don't process the packet return INVALID_PACKET_ID; } } // Does the packet need processing? switch(packetId) { case ID_NEW_INCOMING_CONNECTION: // Request initial data { // Construct the bit stream CBitStream bitStream; // Write the packet id bitStream.Write((PacketId)ID_USER_PACKET_ENUM); // Send the packet Send(&bitStream, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, playerId, false); return INVALID_PACKET_ID; } break; case ID_USER_PACKET_ENUM: // Receive initial data { // Construct the bit stream CBitStream bitStream(ucData, iLength, false); // Read the network version BYTE byteNetworkModuleVersion; if(!bitStream.Read(byteNetworkModuleVersion)) { // Reject the players connection RejectKick(playerId); return INVALID_PACKET_ID; } // Verify the network module version if(byteNetworkModuleVersion != NETWORK_MODULE_VERSION) { // Reject the players connection RejectKick(playerId); return INVALID_PACKET_ID; } // Construct the new player socket CPlayerSocket * pPlayerSocket = new CPlayerSocket; // Set the player socket id pPlayerSocket->playerId = playerId; // Set the player socket binary address pPlayerSocket->ulBinaryAddress = systemAddress.address.addr4.sin_addr.s_addr; // Set the player socket port pPlayerSocket->usPort = ntohs(systemAddress.address.addr4.sin_port); // Add the player socket to the player socket list m_playerSocketList.push_back(pPlayerSocket); // Reset the bit stream for reuse bitStream.Reset(); // Write the packet id bitStream.Write((PacketId)(ID_USER_PACKET_ENUM + 1)); // Send the packet Send(&bitStream, PRIORITY_HIGH, RELIABILITY_RELIABLE_ORDERED, playerId, false); return INVALID_PACKET_ID; } break; case (ID_USER_PACKET_ENUM + 1): // Client is ready return PACKET_NEW_CONNECTION; break; case ID_DISCONNECTION_NOTIFICATION: return PACKET_DISCONNECTED; break; case ID_CONNECTION_LOST: return PACKET_LOST_CONNECTION; break; } // Is the packet a non processed RakNet packet? if(packetId < INTERNAL_PACKET_END) return INVALID_PACKET_ID; // No processing needed return packetId; }
PLUGIN_EXPORT bool PLUGIN_CALL OnPlayerCommandText(int playerid, const char *cmdtext) { char string[128]; int playermoney; char sendername[MAX_PLAYER_NAME]; char giveplayer[MAX_PLAYER_NAME]; char *cmd; int giveplayerid, moneys; // FIXME: const_cast isn't really a good solution cmd = strtok(const_cast<char*>(cmdtext), " "); if(strcmp(cmd, "/help") == 0) { SendPlayerFormattedText(playerid,"Las Venturas Deathmatch: Money Grub Coded By Jax and the SA-MP Team.",0); SendPlayerFormattedText(playerid,"Type: /objective : to find out what to do in this gamemode.",0); SendPlayerFormattedText(playerid,"Type: /givecash [playerid] [money-amount] to send money to other players.",0); SendPlayerFormattedText(playerid,"Type: /tips : to see some tips from the creator of the gamemode.", 0); return true; } if(strcmp(cmd, "/objective") == 0) { SendPlayerFormattedText(playerid,"This gamemode is faily open, there's no specific win / endgame conditions to meet.",0); SendPlayerFormattedText(playerid,"In LVDM:Money Grub, when you kill a player, you will receive whatever money they have.",0); SendPlayerFormattedText(playerid,"Consequently, if you have lots of money, and you die, your killer gets your cash.",0); SendPlayerFormattedText(playerid,"However, you're not forced to kill players for money, you can always gamble in the", 0); SendPlayerFormattedText(playerid,"Casino's.", 0); return true; } if(strcmp(cmd, "/tips") == 0) { SendPlayerFormattedText(playerid,"Spawning with just a desert eagle might sound lame, however the idea of this",0); SendPlayerFormattedText(playerid,"gamemode is to get some cash, get better guns, then go after whoever has the",0); SendPlayerFormattedText(playerid,"most cash. Once you've got the most cash, the idea is to stay alive(with the",0); SendPlayerFormattedText(playerid,"cash intact)until the game ends, simple right?", 0); return true; } if(strcmp(cmd, "/givecash") == 0) { cmd = strtok(NULL, " "); if(cmd == 0 || !strlen(cmd)) { SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash [playerid] [amount]"); return true; } giveplayerid = atoi(cmd); cmd = strtok(NULL, " "); if(cmd == 0 || !strlen(cmd)) { SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givecash [playerid] [amount]"); return true; } moneys = atoi(cmd); if (IsPlayerConnected(giveplayerid)) { GetPlayerName(giveplayerid, giveplayer, MAX_PLAYER_NAME); GetPlayerName(playerid, sendername, MAX_PLAYER_NAME); playermoney = GetPlayerMoney(playerid); if (moneys > 0 && playermoney >= moneys) { GivePlayerMoney(playerid, (0 - moneys)); GivePlayerMoney(giveplayerid, moneys); sprintf(string, "You have sent %s(player: %d), $%d.", giveplayer,giveplayerid, moneys); SendClientMessage(playerid, COLOR_YELLOW, string); sprintf(string, "You have recieved $%d from %s(player: %d).", moneys, sendername, playerid); SendClientMessage(giveplayerid, COLOR_YELLOW, string); ServerLog::Printf("%s(playerid:%d) has transfered %d to %s(playerid:%d)",sendername, playerid, moneys, giveplayer, giveplayerid); } else { SendClientMessage(playerid, COLOR_YELLOW, "Invalid transaction amount."); } } else { sprintf(string, "%d is not an active player.", giveplayerid); SendClientMessage(playerid, COLOR_YELLOW, string); } return true; } return false; }