public void PersonLeave(Person person) { Console.WriteLine($"Worker {person.Name} leave to work"); byeAll -= person.Goodbye; greetAll -= person.Greet; if (byeAll != null) { byeAll.Invoke(person); } }
public void PersonCame(Person person, DateTime time) { Console.WriteLine($"Worker {person.Name} came to work"); if (greetAll != null) { greetAll(person, time); } greetAll += person.Greet; byeAll += person.Goodbye; }
private void handleGoodbyeMessage(GoodbyeMessage msg, IPAddress sender) { // see if we know about this peer SyncPeer _found = _peers.Find((peer) => { return(peer.Address.Equals(sender)); }); // if so, remove from our peer list if (_found != null) { removePeer(_found); } }
public void ProcessGoodbyeMessage(GoodbyeMessage gm) { if (_Client == null) { return; } _Client.Disconnect(); if (_GoodbyeMessageDelegate != null) { _GoodbyeMessageDelegate(); } }
public void processGoodbye(GoodbyeMessage message) { int id = message.GetId; foreach (CubeEntity player in serverCubes) { if (player.Id.Equals(id)) { Destroy(player.GameObject); serverCubes.Remove(player); players.Remove(new PlayerInfo(id, null)); } } }
/// <summary> /// Disconnects from the server. The server is actively notified about disconnection. /// </summary> public void Disconnect() { if (_channel != null && HasSession) { if (_keepSessionAliveTimer != null) { _keepSessionAliveTimer.Stop(); _keepSessionAliveTimer.Dispose(); _keepSessionAliveTimer = null; } byte[] sharedSecret = MessageEncryption ? _sessionId.ToByteArray() : null; var goodbyeMessage = new GoodbyeMessage() { SessionId = _sessionId }; var wireMessage = MessageEncryptionManager.CreateWireMessage( messageType: "goodbye", serializer: Serializer, serializedMessage: Serializer.Serialize(goodbyeMessage), keyPair: _keyPair, sharedSecret: sharedSecret); byte[] rawData = Serializer.Serialize(wireMessage); _goodbyeCompletedWaitHandle.Reset(); _channel.RawMessageTransport.SendMessage(rawData); _goodbyeCompletedWaitHandle.Wait(10000); } _channel?.Disconnect(); _handshakeCompletedWaitHandle?.Reset(); _authenticationCompletedWaitHandle?.Reset(); Identity = null; }
public void Goodbye(GoodbyeDetails details, string reason) { using (IDisposable proxy = mServerProxy as IDisposable) { if (!mGoodbyeSent) { mServerProxy.Goodbye(new GoodbyeDetails(), WampErrors.GoodbyeAndOut); } else { mGoodbyeMessage = new GoodbyeMessage() { Details = details, Reason = reason }; } } TrySetCloseEventArgs(SessionCloseType.Goodbye, details, reason); }
private void RaiseConnectionBroken() { TrySetCloseEventArgs(SessionCloseType.Disconnection); WampSessionCloseEventArgs closeEventArgs = mCloseEventArgs; Interlocked.CompareExchange(ref mIsConnected, 0, 1); GoodbyeMessage goodbyeMessage = mGoodbyeMessage; if (goodbyeMessage != null) { mCloseTask?.TrySetResult(goodbyeMessage); } SetTasksErrorsIfNeeded(new WampConnectionBrokenException(mCloseEventArgs)); mOpenTask = new TaskCompletionSource <bool>(); mCloseTask = null; mCloseEventArgs = null; mGoodbyeMessage = null; OnConnectionBroken(closeEventArgs); }
protected Message getMessage() { byte[] b; int avail; try { //while we're here, look for data in the buffer avail = _sock.Available; if (avail > 0) { buffer.ReadFromSocket(_sock, avail); this.BytesReceived += avail; } //first see if we can actually decode something if (buffer.CanDecode()) { b = buffer.Decode(); } else { return(null); } } catch (Exception ex) { PhazeXLog.LogError(ex, GameLibraryVersion.VersionString, 104); _connected = false; return(null); } Message m = null; if (b.Length == 0) { return(m); } else if (b[0] == (byte)pxMessages.Heartbeat) { m = new HeartBeatMessage(b); } else if (b[0] == (byte)pxMessages.ChangeName) { m = new ChangeNameMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.ChangeNameReject) { m = new ChangeNameRejectMessage(b); } else if (b[0] == (byte)pxMessages.Chat) { m = new ChatMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.CompletedPhaze) { m = new CompletedPhazeMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.CurrentPhaze) { m = new CurrentPhazeMessage(b, this.GameRules); } else if (b[0] == (byte)pxMessages.DiscardSkip) { m = new DiscardSkipMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.DialogMessage) { m = new DialogMessage(b); } else if (b[0] == (byte)pxMessages.ErrorMessage) { m = new ErrorMessage(b); } else if (b[0] == (byte)pxMessages.GameOver) { m = new GameOverMessage(b); } else if (b[0] == (byte)pxMessages.GameRules) { m = new GameRulesMessage(b); } else if (b[0] == (byte)pxMessages.GameStarting) { m = new GameStartingMessage(b); } else if (b[0] == (byte)pxMessages.Goodbye) { m = new GoodbyeMessage(b); } else if (b[0] == (byte)pxMessages.GotCards) { m = new GotCardsMessage(b, this.GameRules); } else if (b[0] == (byte)pxMessages.GotDeckCard) { m = new GotDeckCardMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.GotDiscard) { m = new GotDiscardMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.Hand) { m = new HandMessage(b, this.GameRules); } else if (b[0] == (byte)pxMessages.Login) { m = new LoginMessage(b); } else if (b[0] == (byte)pxMessages.LoginAcknowledgment) { m = new LoginAckMessage(b); } else if (b[0] == (byte)pxMessages.LogOff) { m = new LogOffMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.NewHand) { m = new NewHandMessage(b); } else if (b[0] == (byte)pxMessages.PlayedCardOnTable) { m = new PlayedCardOnTableMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.Ready) { m = new ReadyMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.Scoreboard) { m = new ScoreboardMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.SkipNotification) { m = new SkipNotificationMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.StartGameTimer) { m = new StartGameTimerMessage(b); } else if (b[0] == (byte)pxMessages.Status) { m = new StatusMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.SystemMessage) { m = new SystemMessage(b); } else if (b[0] == (byte)pxMessages.Table) { m = new TableMessage(b, this.GameRules); } else if (b[0] == (byte)pxMessages.TurnEnd) { m = new TurnEndMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.TurnStart) { m = new TurnStartMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.UpdateDiscard) { m = new UpdateDiscardMessage(b, this.GetPlayerIDs(), this.GameRules); } else if (b[0] == (byte)pxMessages.WentOut) { m = new WentOutMessage(b, this.GetPlayerIDs()); } else if (b[0] == (byte)pxMessages.Won) { m = new WonMessage(b, this.GetPlayerIDs()); } else { m = new UnknownMessage(b); } return(m); }