public void ConnectToGameServer(GameServerInformation serverInformation) { GameServerServiceProvider = new ClientServiceProvider( serverInformation.ServerPublicAddress, serverInformation.ServerPort, NetworkObjectParameters.LobbyServerBufferSize, GameServerConsumerAction); GameServerServiceProvider.StartOperation(); }
protected override object CreateBehavior() { var clientProvider = new ClientServiceProvider { CancellationContractFactory = null }; var serviceProvider = new ServiceServiceProvider(); return(new CancellationEndpointBehavior(new CombinedServiceProvider(clientProvider, serviceProvider))); }
public static void LobbyServiceConsumerAction(ClientServiceProvider csp, string[] response) { int service = int.Parse(response[0]); switch (service) { case NetworkObjectParameters.GameServerRegisterRequest: LobbyServerHandler.GameServerRegister(response[1]); break; } }
// HUBS public void LobbyServerConsumerAction(ClientServiceProvider csp, string[] request) { int service = int.Parse(request[0]); switch (service) { case NetworkObjectParameters.LobbyServerServerListRequest: ServerInformationHandler.ServerListHandle(request[1]); break; } }
private ServerInformationBroker() { ActionCallbackDictionary = new Dictionary <int, Action <object> >(); LobbyServerServiceProvider = new ClientServiceProvider( NetworkObjectParameters.LobbyServerInformation.ServerPublicAddress, NetworkObjectParameters.LobbyServerInformation.ServerPort, NetworkObjectParameters.LobbyServerBufferSize, LobbyServerConsumerAction); ActionCallbackDictionary.AddOrReplace(NetworkObjectParameters.GameServerRoomRefreshMetadata, UpdateRoomMetadataAsyncCallback); LobbyServerServiceProvider.StartOperation(); }
public void ConnectToGameServer(GameServerInformation serverInformation) { GameServerServiceProvider = new ClientServiceProvider( serverInformation.ServerPublicAddress, serverInformation.ServerPort, NetworkObjectParameters.LobbyServerBufferSize, GameServerConsumerAction); GameServerServiceProvider.StartOperation(); GameServerServiceProvider.OnDisconnect += OnDisconnect; //If the application fails to send or to receive, force the disconnection GameServerServiceProvider.OnFailToSendMessage = GameServerServiceProvider.OnFailToReceiveMessage = (ex) => { return(true); }; }
private static void RegisterClient(ServiceEndpoint endpoint, Action <ClientCancellationOptions> configureOptions) { if (endpoint.Behaviors.Contains(typeof(CancellationEndpointBehavior))) { throw new InvalidOperationException(Resources.ServiceEndpointUseCancellationTwice); } var options = new ClientCancellationOptions(); configureOptions?.Invoke(options); var provider = new ClientServiceProvider { CancellationContractFactory = options.ContractFactory }; endpoint.Behaviors.Add(new CancellationEndpointBehavior(provider)); }
public static void StartListeningPlayerLoginAttempt(ExtendedConcurrentQueue <byte[]> provider, string param) { try { PlayerController pc = new PlayerController(); Player deserializedPlayer = ObjectWrapper.Deserialize <Player>(param); Player player = pc.LoginPlayer(deserializedPlayer); Player answer = null; if (player != null) { ClientServiceProvider csp = new ClientServiceProvider( NetworkObjectParameters.LobbyServerInformation.ServerLocalAddress, NetworkObjectParameters.LobbyServerInformation.ServerPort, NetworkObjectParameters.LobbyServerBufferSize, (_provider, _request) => { answer = ObjectWrapper.Deserialize <Player>(_request[1]); }); csp.StartOperation(); csp.RequestQueue.Enqueue(NetworkObjectParameters.LobbyServerPlayerUIDRequest, player); while (answer == null) { Thread.Sleep(100); } csp.StopOperation(); deserializedPlayer.Nickname = answer.Nickname; } Console.WriteLine($"- Request for: {deserializedPlayer.Nickname} - {deserializedPlayer.Password} - Player " + ((answer == null) ? "not " : "") + "found"); if (answer == null) { provider.Enqueue(NetworkObjectParameters.LoginServerLoginAttemptRequest, null); return; } // Preparing Player Information Stream Dictionary <AvatarCategory, HashSet <int> > ownedAvatars = pc.RetrievePlayerAvatarList(player); provider.Enqueue(NetworkObjectParameters.LoginServerLoginAttemptRequest, player); if (ownedAvatars != null) { foreach (KeyValuePair <AvatarCategory, HashSet <int> > kvp in ownedAvatars) { //For safety reasons, the maximum integer stream size must be 300 integers. const int maximumSize = 300; for (int i = 0; i < kvp.Value.Count; i += maximumSize) { provider.Enqueue(NetworkObjectParameters.LoginServerLoginAttemptRequest, (int)kvp.Key, kvp.Value.Skip(i).Take(maximumSize).ToList()); } } } //Sends the "EOF" to client provider.Enqueue(NetworkObjectParameters.LoginServerLoginAttemptRequest, 0, null); } catch (Exception ex) { Console.WriteLine($"Error: {ex}"); throw ex; } }
public void Login(GameLauncher gameLauncher, string nickname, string password) { try { //Preparing player variable Player player = new Player() { Nickname = nickname, Password = password }; bool waiting = false; ClientServiceProvider csp = new ClientServiceProvider( NetworkObjectParameters.LoginServerInformation.ServerPublicAddress, NetworkObjectParameters.LoginServerInformation.ServerPort, NetworkObjectParameters.LoginServerBufferSize, (serviceProvider, message) => { if (message.Length == 2) { player = ObjectWrapper.DeserializeRequest <Player>(message[1]); if (player == null) { waiting = true; return; } } else { List <int> idList = ObjectWrapper.DeserializeRequest <List <int> >(message[2]); if (idList == null) { waiting = true; return; } foreach (int i in idList) { player.PlayerAvatarMetadataList.Add(new PlayerAvatarMetadata() { Player = player, AvatarMetadata = new AvatarMetadata() { ID = i, AvatarCategory = (AvatarCategory)int.Parse(message[1]) }, }); } } }); csp.OnFailToEstabilishConnection += () => { Feedback.CreateWarningMessageBox(Language.FailToEstabilishConnection); OnFailToEstabilishConnection(gameLauncher); }; csp.StartOperation(); csp.RequestQueue.Enqueue(NetworkObjectParameters.LoginServerLoginAttemptRequest, player); while (!waiting) { Thread.Sleep(100); } csp.StopOperation(); if (player == null || player.ID == 0) { //Error Feedback.CreateWarningMessageBox(Language.PlayerNotFound); OnFailToEstabilishConnection(gameLauncher); return; } player.LoadOwnedAvatarDictionary(); //Success gameLauncher.TickAction += () => { gameLauncher.Close(); }; Parameter.Player = player; } catch (Exception ex) { Console.WriteLine($"Ex: {ex.Message}"); } }
public void Register(SignUpForm signUpForm, PlayerDTO account) { try { bool waiting = false; Player newPlayer = null; ClientServiceProvider csp = new ClientServiceProvider( NetworkObjectParameters.LoginServerInformation.ServerLocalAddress, NetworkObjectParameters.LoginServerInformation.ServerPort, NetworkObjectParameters.LoginServerBufferSize, (serviceProvider, message) => { newPlayer = ObjectWrapper.DeserializeRequest <Player>(message[1]); waiting = true; }); csp.OnFailToEstabilishConnection += () => { Feedback.CreateWarningMessageBox(Language.FailToEstabilishConnection); OnFailToEstabilishConnection(signUpForm); }; csp.StartOperation(); csp.RequestQueue.Enqueue(NetworkObjectParameters.LoginServerAccountCreationRequest, account); while (!waiting) { Thread.Sleep(100); } csp.StopOperation(); bool wasAccountCreated = true; if (newPlayer == null) { //Unnable to create player (unknown reason) signUpForm.TickAction += () => signUpForm.SetEnableInterfaceElements(true); Feedback.CreateWarningMessageBox(Language.RegisterFailureMessage); return; } string errorMessage = ""; if (newPlayer.Nickname == null) { //Invalid Nickname errorMessage += Language.RegisterFailureNickname; wasAccountCreated = false; } if (newPlayer.Email == null) { //Invalid Email errorMessage += Language.RegisterFailureEmail; wasAccountCreated = false; } if (wasAccountCreated) { //Success signUpForm.TickAction += () => signUpForm.Close(); Feedback.CreateInformationMessageBox($"{Language.RegisterSuccess}"); } else { signUpForm.TickAction += () => signUpForm.SetEnableInterfaceElements(true); Feedback.CreateWarningMessageBox($"{Language.RegisterFailureMessage}{errorMessage}"); } } catch (Exception ex) { Console.WriteLine($"Ex: {ex.Message}"); } }
public void Login(LoginLoadingScreen loadingScreen, string nickname, string password) { try { //Preparing player variable Player player = new Player() { Nickname = nickname, Password = password }; bool waiting = false; ClientServiceProvider csp = new ClientServiceProvider( NetworkObjectParameters.LoginServerInformation.ServerPublicAddress, NetworkObjectParameters.LoginServerInformation.ServerPort, NetworkObjectParameters.LoginServerBufferSize, (serviceProvider, message) => { if (message.Length == 2) { player = ObjectWrapper.Deserialize <Player>(message[1]); if (player == null) { waiting = true; return; } } else { List <int> idList = ObjectWrapper.Deserialize <List <int> >(message[2]); if (idList == null) { waiting = true; return; } foreach (int i in idList) { player.PlayerAvatarMetadataList.Add(new PlayerAvatarMetadata() { Player = player, AvatarMetadata = new AvatarMetadata() { ID = i, AvatarCategory = (AvatarCategory)int.Parse(message[1]) }, }); } } }); csp.OnFailToEstabilishConnection += loadingScreen.OnFailToStablishConnection; csp.StartOperation(); csp.RequestQueue.Enqueue(NetworkObjectParameters.LoginServerLoginAttemptRequest, player); while (!waiting) { Thread.Sleep(100); } csp.StopOperation(); if (player == null || player.ID == 0) { loadingScreen.OnFailToFindPlayer(); return; } player.LoadOwnedAvatarDictionary(); //Success Parameter.Player = player; loadingScreen.Close(DialogResult.OK); } catch (Exception ex) { Console.WriteLine($"Ex: {ex.Message}"); } }
public void Register(SignUpLoadingScreen signUpLoadingScreen, PlayerDTO account) { try { bool waiting = false; Player newPlayer = null; ClientServiceProvider csp = new ClientServiceProvider( NetworkObjectParameters.LoginServerInformation.ServerPublicAddress, NetworkObjectParameters.LoginServerInformation.ServerPort, NetworkObjectParameters.LoginServerBufferSize, (serviceProvider, message) => { newPlayer = ObjectWrapper.Deserialize <Player>(message[1]); waiting = true; }); csp.OnFailToEstabilishConnection += signUpLoadingScreen.OnFailToStablishConnection; csp.StartOperation(); csp.RequestQueue.Enqueue(NetworkObjectParameters.LoginServerAccountCreationRequest, account); while (!waiting) { Thread.Sleep(100); } csp.StopOperation(); if (newPlayer == null) { //Unnable to create player (unknown reason) signUpLoadingScreen.OnFailToCreateAccount(); return; } string errorMessage = ""; //Invalid Nickname if (newPlayer.Nickname == null) { errorMessage += Language.RegisterFailureNickname; } //Invalid Email if (newPlayer.Email == null) { errorMessage += Language.RegisterFailureEmail; } //Fail if (errorMessage.Length > 0) { signUpLoadingScreen.OnFailToCreateAccount(); return; } //Success signUpLoadingScreen.OnCreateAccount(); } catch (Exception ex) { Console.WriteLine($"Ex: {ex.Message}"); } }
public void GameServerConsumerAction(ClientServiceProvider csp, string[] request) { int service = int.Parse(request[0]); object answer; #if DEBUG Console.WriteLine(service + "|" + request[1]); #endif switch (service) { case NetworkObjectParameters.GameServerPlayerAccessRequest: answer = ObjectWrapper.Deserialize <bool>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerPlayerAccessRequest](answer); break; case NetworkObjectParameters.GameServerRoomListCreateRoom: answer = ObjectWrapper.Deserialize <RoomMetadata>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerRoomListCreateRoom](answer); break; case NetworkObjectParameters.GameServerRoomListRequestList: answer = ObjectWrapper.Deserialize <RoomMetadata>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerRoomListRequestList](answer); break; case NetworkObjectParameters.GameServerRoomListRoomEnter: answer = ObjectWrapper.Deserialize <RoomMetadata>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerRoomListRoomEnter](answer); break; case NetworkObjectParameters.GameServerRoomRefreshMetadata: answer = ObjectWrapper.Deserialize <RoomMetadata>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerRoomRefreshMetadata](answer); break; case NetworkObjectParameters.GameServerRoomLeaveRoom: answer = ObjectWrapper.Deserialize <bool>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerRoomLeaveRoom](answer); break; case NetworkObjectParameters.GameServerRoomReadyRoom: ActionCallbackDictionary[NetworkObjectParameters.GameServerRoomReadyRoom](null); break; case NetworkObjectParameters.GameServerRoomRefreshLoadingPercentage: answer = ObjectWrapper.Deserialize <KeyValuePair <int, int> >(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerRoomRefreshLoadingPercentage](answer); break; case NetworkObjectParameters.GameServerRoomStartInGameScene: ActionCallbackDictionary[NetworkObjectParameters.GameServerRoomStartInGameScene](null); break; case NetworkObjectParameters.GameServerInGameStartMatch: answer = ObjectWrapper.Deserialize <List <SyncMobile> >(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerInGameStartMatch](answer); break; case NetworkObjectParameters.GameServerInGameRefreshSyncMobile: answer = ObjectWrapper.Deserialize <SyncMobile>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerInGameRefreshSyncMobile](answer); break; case NetworkObjectParameters.GameServerInGameRequestNextPlayerTurn: answer = ObjectWrapper.Deserialize <MatchManager>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerInGameRequestNextPlayerTurn](answer); break; case NetworkObjectParameters.GameServerInGameRequestShot: answer = ObjectWrapper.Deserialize <SyncMobile>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerInGameRequestShot](answer); break; case NetworkObjectParameters.GameServerInGameRequestItemUsage: answer = ObjectWrapper.Deserialize <SyncMobile>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerInGameRequestItemUsage](answer); break; case NetworkObjectParameters.GameServerInGameRequestDeath: answer = ObjectWrapper.Deserialize <SyncMobile>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerInGameRequestDeath](answer); break; case NetworkObjectParameters.GameServerInGameRequestGameEnd: answer = ObjectWrapper.Deserialize <PlayerTeam>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerInGameRequestGameEnd](answer); break; case NetworkObjectParameters.GameServerInGameRequestDisconnect: answer = ObjectWrapper.Deserialize <SyncMobile>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerInGameRequestDisconnect](answer); break; case NetworkObjectParameters.GameServerInGameRequestDamage: answer = ObjectWrapper.Deserialize <int>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerInGameRequestDamage](answer); break; //Chat case NetworkObjectParameters.GameServerChatJoinChannel: answer = ObjectWrapper.Deserialize <int>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerChatJoinChannel](answer); break; case NetworkObjectParameters.GameServerChatEnter: answer = ObjectWrapper.Deserialize <Player>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerChatEnter](answer); break; case NetworkObjectParameters.GameServerChatLeave: answer = ObjectWrapper.Deserialize <Player>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerChatLeave](answer); break; case NetworkObjectParameters.GameServerChatSendPlayerMessage: answer = ObjectWrapper.Deserialize <PlayerMessage>(request[1]); if (ObjectValidator.ValidateAndModify((PlayerMessage)answer)) { ActionCallbackDictionary[NetworkObjectParameters.GameServerChatSendPlayerMessage](answer); } break; case NetworkObjectParameters.GameServerChatSendSystemMessage: answer = ObjectWrapper.Deserialize <List <CustomMessage> >(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerChatSendSystemMessage](answer); break; //Avatar Shop case NetworkObjectParameters.GameServerAvatarShopBuyAvatarGold: answer = ObjectWrapper.Deserialize <AvatarMetadata>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerAvatarShopBuyAvatarGold](answer); break; case NetworkObjectParameters.GameServerAvatarShopBuyAvatarCash: answer = ObjectWrapper.Deserialize <AvatarMetadata>(request[1]); ActionCallbackDictionary[NetworkObjectParameters.GameServerAvatarShopBuyAvatarCash](answer); break; } }