Exemplo n.º 1
0
 bool WaitPlayerConfirm(ServerConnectionMessagesHandler receiver)
 {
     bool result = false;
       for(int i = 0; i < 20; i++)
       {
     if(receiver.Confirmed)
     {
       result = true;
       break;
     }
     Thread.Sleep(500);
       }
       return result;
 }
Exemplo n.º 2
0
 void ValidatePlayer(ServerConnectionMessagesHandler receiver, out ConnectionResult result, out string refuseReason)
 {
     refuseReason = string.Empty;
       result = ConnectionResult.Accepted;
       Version clientVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
       if(!new Version(receiver.Handshake.ClientVersion).Equals(clientVersion))
       {
     result = ConnectionResult.VersionMismatch;
     refuseReason = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_VERSIONMISMATCH");
       }
       else if(gameIsRunning)
       {
     result = ConnectionResult.GameIsRunning;
     refuseReason = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_GAMEISRUNNING");
       }
       else if(receiver.Handshake.StartMode != this.startMode)
       {
     result = ConnectionResult.InvalidStartMode;
     refuseReason = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_INVALIDSTARTMODE");
       }
       else if(receiver.Handshake.PlayerInfo.NickName == Player.NickName ||
     connections.Any(e => e.Value.Handshake.PlayerInfo.NickName == receiver.Handshake.PlayerInfo.NickName))
       {
     result = ConnectionResult.NicknameDuplicated;
     refuseReason = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_NICKNAMEDUPLICATED");
       }
       else if(receiver.Handshake.GameDatabaseCRC != servicesProvider.GameDatabaseCrc)
       {
     result = ConnectionResult.GameDatabaseMismatch;
     refuseReason = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_GAMEDATAMISMATCH");
       }
       //else if(receiver.Handshake.CardDatabaseCRC != servicesProvider.CardDatabaseCrc)
       //{
       //  result = ConnectionResult.CardDatabaseMismatch;
       //  refuseReason = servicesProvider.StringService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_CARDDATAMISMATCH");
       //}
       else if(passwordRequired && string.IsNullOrEmpty(receiver.Handshake.Password))
       {
     result = ConnectionResult.PasswordRequired;
     refuseReason = servicesProvider.SystemStringsService.GetString("NEW_SERVER_GAME_DIALOG", "MSG_CONNECTIONREFUSED_PASSWORDREQUIRED");
       }
 }
Exemplo n.º 3
0
 bool WaitHandshake(ServerConnectionMessagesHandler receiver)
 {
     bool result = false;
       for(int i = 0; i < 20; i++)
       {
     if(receiver.Handshake != null)
     {
       result = true;
       break;
     }
     Thread.Sleep(500);
       }
       return result;
 }
Exemplo n.º 4
0
 void netMessageService_ClientConnected(object sender, ServiceNetClient client)
 {
     using(var connectionMessagesHandler = new ServerConnectionMessagesHandler(client))
       {
     if(!WaitHandshake(connectionMessagesHandler))
     {
       if(Console != null)
     Console.WriteLine(MessageCategory.Warning, "Opponent handshake not received");
     }
     else
     {
       ConnectionResult result;
       string refuseReason;
       ValidatePlayer(connectionMessagesHandler, out result, out refuseReason);
       HandshakeResponse handshakeResponse = new HandshakeResponse()
       {
     Deck = new DeckDataContract(deck),
     PlayerInfo = Player,
     ConnectionResult = result,
       };
       Thread.Sleep(100);
       client.SendMessage(handshakeResponse);
       if(result != ConnectionResult.Accepted)
       {
     if(Console != null)
       Console.WriteLine(MessageCategory.Warning, string.Concat("Player ", connectionMessagesHandler.Handshake.PlayerInfo.NickName, " refused: ", refuseReason));
       }
       else
       {
     if(!WaitPlayerConfirm(connectionMessagesHandler))
     {
       if(Console != null)
         Console.WriteLine(MessageCategory.Warning, string.Concat("Player ", connectionMessagesHandler.Handshake.PlayerInfo.NickName, " hasn't confirmed the connection."));
     }
     else
     {
       client.Disconnected += new EventHandler(client_Disconnected);
       lock(syncObject)
         connections.Add(client, connectionMessagesHandler);
       PlayerAccountData connectedPlayer = new PlayerAccountData()
       {
         Info = connectionMessagesHandler.Handshake.PlayerInfo,
         Deck = new DeckItem(connectionMessagesHandler.Handshake.Deck),
         Password = connectionMessagesHandler.Handshake.Password
       };
       OnPlayerConnected(client, connectedPlayer);
     }
       }
     }
       }
 }