void OnUserConnected(IPlayer player) { // Check if user is in the list of disconnected player bool playerInList = false; ulong thisPlayerId = Convert.ToUInt64(player.Id); DisconnectData thisPlayerData = null; foreach (DisconnectData data in disconnectedPlayers) { if (data.userId == thisPlayerId) { playerInList = true; thisPlayerData = data; } } // Player is in the list if (playerInList && thisPlayerData != null) { // Compensate the player ItemDefinition theItem = ItemManager.FindItemDefinition(thisPlayerData.itemShortName); Item item = ItemManager.CreateByItemID(theItem.itemid, thisPlayerData.amount); BasePlayer thisPlayer = player.Object as BasePlayer; thisPlayer.GiveItem(item); // Generate message string message = lang.GetMessage("Compensate", this, thisPlayer.UserIDString); thisPlayer.ChatMessage(string.Format(message, thisPlayerData.amount, theItem.displayName)); // Remove user from list disconnectedPlayers.Remove(thisPlayerData); } }
protected override Task OnDisconnected(IRequest request, string connectionId, bool stopCalled) { var data = new DisconnectData(stopCalled, request.Environment.Get <string>(MemoryHost.InstanceNameKey)); Assert.True(_disconnectCounter.TryWrite(data), "Disconnect counter channel should be unbounded!"); return(base.OnDisconnected(request, connectionId, stopCalled)); }
void OnUserDisconnected(IPlayer player) { // Check if user got join the raffle bool didJoinRaffle = false; ulong thisPlayerId = Convert.ToUInt64(player.Id); foreach (ulong playerId in joinedPlayersId) { if (playerId == thisPlayerId) { // User is in the list didJoinRaffle = true; } } if (didJoinRaffle) { // Create the data then add the data into the list to compensate them when they connect later on DisconnectData data = new DisconnectData(thisPlayerId, raffleJoinName, raffleJoinAmount); disconnectedPlayers.Add(data); // Remove them from the list joinedPlayersId.Remove(thisPlayerId); } bool didJoinBlackjack = false; BlackjackData thisData = null; foreach (BlackjackData bjData in blackjackDatas) { if (bjData.thisPlayer.userID == thisPlayerId) { // User is in the list didJoinBlackjack = true; thisData = bjData; } } if (didJoinBlackjack) { // Create the data then add the data into the list to compensate them when they connect later on DisconnectData data = new DisconnectData(thisPlayerId, thisData.item, thisData.amount); disconnectedPlayers.Add(data); // Remove them from the list blackjackDatas.Remove(thisData); } }
/// <summary> /// Disconnects the hosted visual on a channel. /// </summary> private void DisconnectHostedVisual( DUCE.Channel channel, bool removeChannelFromCollection) { Dispatcher channelDispatcher; if (_target != null && _connectedChannels.TryGetValue(channel, out channelDispatcher)) { // Adding commands to a channel is not thread-safe, // we must do the actual work on the same dispatcher thread // where the connection happened. if (channelDispatcher != null && channelDispatcher.CheckAccess()) { Disconnect(channel, channelDispatcher, _proxy.GetHandle(channel), _target._contentRoot.GetHandle(channel), _target._contentRoot); } else { // marshal to the right thread if (channelDispatcher != null) { DispatcherOperation op = channelDispatcher.BeginInvoke( DispatcherPriority.Normal, new DispatcherOperationCallback(DoDisconnectHostedVisual), channel); _disconnectData = new DisconnectData( op: op, channel: channel, dispatcher: channelDispatcher, hostVisual: this, hostHandle: _proxy.GetHandle(channel), targetHandle: _target._contentRoot.GetHandle(channel), contentRoot: _target._contentRoot, next: _disconnectData); } } if (removeChannelFromCollection) { _connectedChannels.Remove(channel); } } }
public DisconnectData(DispatcherOperation op, DUCE.Channel channel, Dispatcher dispatcher, HostVisual hostVisual, DUCE.ResourceHandle hostHandle, DUCE.ResourceHandle targetHandle, DUCE.MultiChannelResource contentRoot, DisconnectData next) { DispatcherOperation = op; Channel = channel; ChannelDispatcher = dispatcher; HostVisual = hostVisual; HostHandle = hostHandle; TargetHandle = targetHandle; ContentRoot = contentRoot; Next = next; }
/// <summary> /// Perform a pending disconnect for the given channel. /// This method should be called under the CompositionEngineLock, /// on the thread that owns the channel. It can be called either /// from the dispatcher callback DoDisconnectHostedVisual or /// from FreeContent, whichever happens to occur first. /// </summary> /// <returns> /// True if a matching request was found and processed. False if not. /// </returns> private bool DoPendingDisconnect(DUCE.Channel channel) { DisconnectData disconnectData = _disconnectData; DisconnectData previous = null; // search the list for an entry matching the given channel while (disconnectData != null && (disconnectData.HostVisual != this || disconnectData.Channel != channel)) { previous = disconnectData; disconnectData = disconnectData.Next; } // if no match found, do nothing if (disconnectData == null) { return(false); } // remove the matching entry from the list if (previous == null) { _disconnectData = disconnectData.Next; } else { previous.Next = disconnectData.Next; } // cancel the dispatcher callback, (if we're already in it, // this call is a no-op) disconnectData.DispatcherOperation.Abort(); // do the actual disconnect Disconnect(disconnectData.Channel, disconnectData.ChannelDispatcher, disconnectData.HostHandle, disconnectData.TargetHandle, disconnectData.ContentRoot); return(true); }
public void Disconnect(DisconnectData data) { Client.inst.onDisconected(data); }
void Handle(DisconnectData data) { gameState.Disconnects.Add(data); }
public void onDisconected(DisconnectData disconnectData) { _welcomeDiv.innerHTML = "Disconected."; }