private void ClientSocket_ConnectCompleted(object sender, TcpCompletedEventArgs e) { if (!e.Error) { Console.WriteLine($"Connected to {(IPEndPoint)e.Data}"); PacketProtocol = new PacketProtocol(ClientSocket); PacketProtocol.PacketArrived += PacketProtocol_PacketArrived; PacketProtocol.Start(); Console.WriteLine("Sending client info..."); PacketProtocol.SendPacket(ClientSocket, new Packet { Content = World.LocalPlayer, Type = PacketType.PLAYER_INFO }); World.AddPlayer(World.LocalPlayer); ConnectedToServer?.Invoke(ClientSocket.RemoteEndPoint.ToString(), World.LocalPlayer.Name); _connected = true; } else { CriticalErrorOccured($"Произошла критическая ошибка!\n{((Exception)e.Data).Message}"); } }
protected void RaiseConnected() { IsRunning = true; KeepAliveTimer.Enabled = true; ConnectedToServer?.Invoke(this); _disconnectedInvoked = false; }
private void ConnectTo() { if (!IsConnected) { try { IsWaitingForConnect = true; TcpClient = new TcpClient(RemoteIp, Port); NetworkStream = TcpClient.GetStream(); IsConnected = true; ConnectedToServer?.Invoke(this, new ConnectToServerEventArgs(true)); } catch (Exception ex) { ConnectedToServer?.Invoke(this, new ConnectToServerEventArgs(false, ex.Message)); } finally { IsWaitingForConnect = false; } } else { ConnectedToServer?.Invoke(this, new ConnectToServerEventArgs(true, "已处于连接状态")); } }
private static NetworkStream ConnectToServer() { // localhost: serverSocket = new Socket(serverEndpoint.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); serverSocket.Connect(serverEndpoint); ConnectedToServer?.Invoke(null, EventArgs.Empty); return(new NetworkStream(serverSocket)); }
private void NotifierOnConnectedToServer(object sender, NotifierEventArgs <ConnectionEstablished> notifierEventArgs) { if (notifierEventArgs?.Payload != null) { Me = new MeseClient(_tcpClient, notifierEventArgs.Payload.Me); Friends = notifierEventArgs.Payload.Others.ToList(); ConnectedToServer?.Invoke(this, notifierEventArgs); } }
public async Task <ServiceDataResult <ConnectionData> > OpenConnectionAsync(string username, string hostname, int port) { try { if (IsConnecting) { return(new ServiceDataResult <ConnectionData>("Already connecting")); } if (IsConnected) { return(new ServiceDataResult <ConnectionData>("Already connected")); } IsConnecting = true; SetHubConnection(hostname, port); await _hubConnection.Start(); } catch (HttpRequestException e) { IsConnecting = false; return(new ServiceDataResult <ConnectionData>() { IsSucessful = false, ErrorMessage = e.Message }); } var task = _hubProxy.Invoke <ServiceDataResult <ConnectionData> >("Join", username); await task; IsConnecting = false; if (task.Result.IsSucessful) { IsConnected = true; ConnectedToServer?.Invoke(this, new ConnectedToServerEventArgs() { Username = username, ConnectionData = task.Result.Data }); } else { ClearConnection(); } return(task.Result); }
private void OnReceive(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod) { GameKey key = (GameKey)reader.GetByte(); if (key == GameKey.JoinedGame) { IsConnected = true; ConnectedToServer?.Invoke(this, EventArgs.Empty); Log.Information("Client successfully connected to server at {endPoint}", peer.EndPoint); } else { GameKeyPackage package = new GameKeyPackage(key, reader, peer); GameEvent?.Invoke(this, package); } reader.Recycle(); }
public async Task <ServiceDataResult <ConnectionData> > OpenConnectionAsync(string username, string hostname, int port) { if (!IsConnecting && !IsConnected) { IsConnecting = true; await Task.Factory.StartNew( () => { Thread.Sleep(2000); }); _timeServerTimer.Start(); _joeTimer.Start(); ConnectedToServer?.Invoke(this, null); IsConnecting = false; IsConnected = true; } return(new ServiceDataResult <ConnectionData>(new ConnectionData(new List <string> { _timeServer }, "test server"))); }
/// <summary> /// Raises the event <see cref="ConnectedToServer"/>. /// </summary> protected internal void RaiseConnectedToServer() { _log.Debug(nameof(RaiseConnectedToServer)); ConnectedToServer?.Invoke(this, EventArgs.Empty); }
public override void OnConnectedToMaster() { PhotonNetwork.JoinRandomRoom(); ConnectedToServer?.Invoke(); }
public void OnConnectedToServer() { ConnectedToServer?.Invoke(this, new ConnectedToServer()); }
// Fired when Bluetooth client successfully connected to the Bluetooth server // Provides BluetoothDevice of server device private void JavaConnectedToServerHandler(string deviceAddress) { ConnectedToServer?.Invoke(GetDeviceFromAddress(deviceAddress)); }
private void OnConnectionChanged(ClientConnectionEventArgs e) { ConnectedToServer?.Invoke(this, e); }
private void WelcomeHandler(ResponseArgs args) { _id = JsonConvert.DeserializeObject <string>(args.Text); ConnectedToServer?.Invoke(this, new ConnectedToServerEventArgs(_id)); Debug.WriteLine(_id); }
public override void OnConnectedToMaster() { PhotonNetwork.JoinOrCreateRoom(_roomName, RoomOptions, null); ConnectedToServer?.Invoke(); }
protected virtual void Client_PacketReceived(Packet packet) { #region LOGGING Log(packet); #endregion LOGGING //Ready to go, only disabled since it is currently unusued /*if (packet.Type != PacketType.Acknowledgement) * { * Send(packet.From, new Packet(new Acknowledgement() * { * PacketId = packet.Id * })); * }*/ if (packet.Type == PacketType.Acknowledgement) { Acknowledgement acknowledgement = packet.SpecificPacket as Acknowledgement; AckReceived?.Invoke(acknowledgement, packet.From); } else if (packet.Type == PacketType.Event) { Event @event = packet.SpecificPacket as Event; switch (@event.Type) { case Event.Types.EventType.CoordinatorAdded: AddCoordinatorReceived(@event.ChangedObject.Unpack <Coordinator>()); break; case Event.Types.EventType.CoordinatorLeft: RemoveCoordinatorReceived(@event.ChangedObject.Unpack <Coordinator>()); break; case Event.Types.EventType.MatchCreated: AddMatchReceived(@event.ChangedObject.Unpack <Match>()); break; case Event.Types.EventType.MatchUpdated: UpdateMatchReceived(@event.ChangedObject.Unpack <Match>()); break; case Event.Types.EventType.MatchDeleted: DeleteMatchReceived(@event.ChangedObject.Unpack <Match>()); break; case Event.Types.EventType.PlayerAdded: AddPlayerReceived(@event.ChangedObject.Unpack <Player>()); break; case Event.Types.EventType.PlayerUpdated: UpdatePlayerReceived(@event.ChangedObject.Unpack <Player>()); break; case Event.Types.EventType.PlayerLeft: RemovePlayerReceived(@event.ChangedObject.Unpack <Player>()); break; case Event.Types.EventType.QualifierEventCreated: AddQualifierEventReceived(@event.ChangedObject.Unpack <QualifierEvent>()); break; case Event.Types.EventType.QualifierEventUpdated: UpdateQualifierEventReceived(@event.ChangedObject.Unpack <QualifierEvent>()); break; case Event.Types.EventType.QualifierEventDeleted: DeleteQualifierEventReceived(@event.ChangedObject.Unpack <QualifierEvent>()); break; case Event.Types.EventType.HostAdded: break; case Event.Types.EventType.HostRemoved: break; default: Logger.Error($"Unknown command received!"); break; } } else if (packet.Type == PacketType.ConnectResponse) { var response = packet.SpecificPacket as ConnectResponse; if (response.Response.Type == Response.Types.ResponseType.Success) { switch (response.UserCase) { case ConnectResponse.UserOneofCase.Coordinator: SelfObject = response.Coordinator; Self = new User { Id = response.Coordinator.Id, Name = response.Coordinator.Name }; break; case ConnectResponse.UserOneofCase.Player: SelfObject = response.Player; Self = new User { Id = response.Player.Id, Name = response.Player.Name }; break; } State = response.State; ConnectedToServer?.Invoke(response); } else if (response.Response.Type == Response.Types.ResponseType.Fail) { FailedToConnectToServer?.Invoke(response); } } else if (packet.Type == PacketType.SongFinished) { PlayerFinishedSong?.Invoke(packet.SpecificPacket as SongFinished); } }
protected virtual void OnPlayerConnected(EventArgs e) { ConnectedToServer?.Invoke(this, e); }
protected virtual void OnConnectionEstablisehd(uint clientId) { ConnectedToServer?.Invoke(clientId); }
public void OnConnectedToServer(object sender, NotifierEventArgs <ConnectionEstablished> eventArgs) { ConnectedToServer?.Invoke(sender, eventArgs); }
protected virtual void Client_PacketRecieved(Packet packet) { #region LOGGING string secondaryInfo = string.Empty; if (packet.Type == PacketType.PlaySong) { secondaryInfo = (packet.SpecificPacket as PlaySong).Beatmap.LevelId + " : " + (packet.SpecificPacket as PlaySong).Beatmap.Difficulty; } else if (packet.Type == PacketType.LoadSong) { secondaryInfo = (packet.SpecificPacket as LoadSong).LevelId; } else if (packet.Type == PacketType.Command) { secondaryInfo = (packet.SpecificPacket as Command).CommandType.ToString(); } else if (packet.Type == PacketType.Event) { secondaryInfo = (packet.SpecificPacket as Event).Type.ToString(); if ((packet.SpecificPacket as Event).Type == Event.EventType.PlayerUpdated) { secondaryInfo = $"{secondaryInfo} from ({((packet.SpecificPacket as Event).ChangedObject as Player).Name} : {((packet.SpecificPacket as Event).ChangedObject as Player).DownloadState}) : ({((packet.SpecificPacket as Event).ChangedObject as Player).PlayState} : {((packet.SpecificPacket as Event).ChangedObject as Player).Score} : {((packet.SpecificPacket as Event).ChangedObject as Player).StreamDelayMs})"; } else if ((packet.SpecificPacket as Event).Type == Event.EventType.MatchUpdated) { secondaryInfo = $"{secondaryInfo} ({((packet.SpecificPacket as Event).ChangedObject as Match).SelectedDifficulty})"; } } Logger.Debug($"Recieved {packet.ToBytes().Length} bytes: ({packet.Type}) ({secondaryInfo})"); #endregion LOGGING //Ready to go, only disabled since it is currently unusued /*if (packet.Type != PacketType.Acknowledgement) * { * Send(packet.From, new Packet(new Acknowledgement() * { * PacketId = packet.Id * })); * }*/ if (packet.Type == PacketType.Acknowledgement) { Acknowledgement acknowledgement = packet.SpecificPacket as Acknowledgement; AckReceived?.Invoke(acknowledgement, packet.From); } else if (packet.Type == PacketType.Event) { Event @event = packet.SpecificPacket as Event; switch (@event.Type) { case Event.EventType.CoordinatorAdded: AddCoordinatorRecieved(@event.ChangedObject as MatchCoordinator); break; case Event.EventType.CoordinatorLeft: RemoveCoordinatorRecieved(@event.ChangedObject as MatchCoordinator); break; case Event.EventType.MatchCreated: AddMatchRecieved(@event.ChangedObject as Match); break; case Event.EventType.MatchUpdated: UpdateMatchRecieved(@event.ChangedObject as Match); break; case Event.EventType.MatchDeleted: DeleteMatchRecieved(@event.ChangedObject as Match); break; case Event.EventType.PlayerAdded: AddPlayerRecieved(@event.ChangedObject as Player); break; case Event.EventType.PlayerUpdated: UpdatePlayerRecieved(@event.ChangedObject as Player); break; case Event.EventType.PlayerLeft: RemovePlayerRecieved(@event.ChangedObject as Player); break; default: Logger.Error($"Unknown command recieved!"); break; } } else if (packet.Type == PacketType.ConnectResponse) { var response = packet.SpecificPacket as ConnectResponse; if (response.Type == ConnectResponse.ResponseType.Success) { Self = response.Self; State = response.State; ConnectedToServer?.Invoke(response); } else if (response.Type == ConnectResponse.ResponseType.Fail) { FailedToConnectToServer?.Invoke(response); } } else if (packet.Type == PacketType.SongFinished) { PlayerFinishedSong?.Invoke(packet.SpecificPacket as SongFinished); } }
protected void InvokeConnected(SocketClient a) { IsRunning = true; ConnectedToServer?.Invoke(a); _disconnectedInvoked = false; }
protected void RaiseConnected() { IsRunning = true; ConnectedToServer?.Invoke(this); _disconnectedInvoked = false; }