/* * Client has pushed RockOnBtn or SellOutBtn */ void RockOnOrSellOutHandler(string evt, byte[] playerChoice, VMEODClient client) { if (playerChoice == null) { return; } if (Lobby.GetPlayerSlot(client) == -1) { return; } var slot = Lobby.GetSlotData(client); if (slot != null) { slot.RockOn = (playerChoice[0] == 1); } }
void SetPlayerLetter(string evt, string body, VMEODClient client) { //Only the controller updates this if (Controller == null) { return; } //If we don't recognise the letter, ignore the request var letter = VMEODPaperChaseLetters.A; if (!short.TryParse(body, out letter) || letter < VMEODPaperChaseLetters.A || letter > VMEODPaperChaseLetters.C) { return; } //Make sure they are still a player var playerSlot = Lobby.GetPlayerSlot(client); if (playerSlot == -1) { return; } var data = Lobby.GetSlotData(playerSlot); if (data.Letter != null) { //You can't change your mind! return; } Controller.SendOBJEvent(new VMEODEvent((short)VMEODPaperChaseObjEvent.SetLetter, (short)(letter | (short)((playerSlot + 1) << 8)))); //lo: letter, hi: FREESO player id data.Letter = letter; BroadcastPlayerLetters(); CheckAllLettersSet(); }
public void TradeOffer(string evt, string data, VMEODClient client) { if (data.Length == 0 || !Lobby.IsFull() || Locked) { return; } var mySlot = Lobby.GetPlayerSlot(client); var other = Lobby.Players[mySlot ^ 1]; var myData = Lobby.GetSlotData(mySlot); switch (data[0]) { case 'i': //inventory item //get this inventory item and add it to the slot var inv = data.Substring(1).Split('|'); if (inv.Length < 2) { return; } uint itemID; if (!uint.TryParse(inv[0], out itemID)) { return; } int slotID; if (!int.TryParse(inv[1], out slotID) || slotID > 4) { return; } if (itemID == 0) { //clear a slot lock (this) { ResetTradeTime(); myData.ObjectOffer[slotID] = null; BroadcastTradeData(true); } } else { client.vm.GlobalLink.RetrieveFromInventory(client.vm, itemID, client.Avatar.PersistID, false, (uint guid, byte[] odata) => { if (guid != 0) { lock (this) { ResetTradeTime(); //if this item is already on the offer, do nothing. if (Array.FindIndex(myData.ObjectOffer, x => x != null && x.PID == itemID) > -1) { client.Send("trade_error", ((int)VMEODSecureTradeError.ALREADY_PRESENT).ToString()); BroadcastTradeData(false); return; } var item = Content.Content.Get().WorldCatalog.GetItemByGUID(guid); if (item != null && item.Value.DisableLevel > 1 && client.Avatar.AvatarState.Permissions < VMTSOAvatarPermissions.Admin) { client.Send("trade_error", ((int)VMEODSecureTradeError.UNTRADABLE_OBJECT).ToString()); BroadcastTradeData(false); return; } myData.ObjectOffer[slotID] = new VMEODSecureTradeObject(guid, itemID, odata); BroadcastTradeData(true); } } else { client.Send("trade_error", ((int)VMEODSecureTradeError.MISSING_OBJECT).ToString()); BroadcastTradeData(false); } }); } break; case 'm': //money //do we have the correct amount of money? int amount; if (!int.TryParse(data.Substring(1), out amount) || amount < 0) { return; } if (amount != 0) { //check if the player does have this money. it will be checked again when the transaction occurs. client.vm.GlobalLink.PerformTransaction(client.vm, true, client.Avatar.PersistID, other.Avatar.PersistID, amount, (bool success, int transferAmount, uint uid1, uint budget1, uint uid2, uint budget2) => { if (success) { lock (this) { ResetTradeTime(); myData.MoneyOffer = amount; BroadcastTradeData(true); } } else { client.Send("trade_error", ((int)VMEODSecureTradeError.MISSING_MONEY).ToString()); BroadcastTradeData(false); } }); } break; case 'p': //property //first of all... do we actually own a property? what's its id? bool withObjects = data[1] == 'o'; int pSlotID; if (!int.TryParse(data.Substring(2), out pSlotID) || pSlotID < 0) { return; } //if we're already offering a property and it's not in our slot, fail. //will need to redo this after we find the property and count its objects var index = -1; lock (this) index = Array.FindIndex(myData.ObjectOffer, x => x != null && x.LotID > 0); if (index > 0 && index != pSlotID) { client.Send("trade_error", ((int)VMEODSecureTradeError.ALREADY_PRESENT).ToString()); return; } client.vm.GlobalLink.FindLotAndValue(client.vm, client.Avatar.PersistID, (uint lotID, int objectCount, long objectValue, string lotName) => { if (lotID != 0) { lock (this) { ResetTradeTime(); index = -1; index = Array.FindIndex(myData.ObjectOffer, x => x != null && x.LotID > 0); if (index > 0 && index != pSlotID) { client.Send("trade_error", ((int)VMEODSecureTradeError.ALREADY_PRESENT).ToString()); return; } var obj = new VMEODSecureTradeObject((uint)((withObjects)?2:1), 1, null); obj.LotID = lotID; obj.LotName = lotName; if (withObjects) { obj.ObjectCount = objectCount; obj.ObjectValue = objectValue; } myData.ObjectOffer[pSlotID] = obj; BroadcastTradeData(true); } } else { client.Send("trade_error", ((int)VMEODSecureTradeError.MISSING_MONEY).ToString()); BroadcastTradeData(false); } }); break; case 'a': if (TicksToAcceptable > 0) { return; } lock (this) { myData.Accepted = true; if (Lobby.GetSlotData(mySlot ^ 1).Accepted) { TryCompleteTrade(); } else { BroadcastTradeData(false); } } break; } }