Example #1
0
 //from the server
 public void SendClientMess(NetworkPlayer player, NetworkClient.MessType_ToClient messType, params string[] args)
 {
     DebugConsole.LogWarning("Sending message to player " + player + ": " + messType.ToString());
     if (args != null && args.Length > 0)
     {
         DebugConsole.Log("args: " + RayToString(args, ","));
     }
     if (Network.isServer)
     {
         //DebugConsole.Log( "SendClientMess( int messType )" );
         if (args != null && args.Length > 0)
         {
             networkView.RPC("FromServerWString", player, networkView.viewID, (int)messType, RayToString(args, ","));
         }
         else
         {
             //DebugConsole.LogWarning( "null or zero length arguments to SendClientMess." );
             networkView.RPC("FromServerNoArgs", player, networkView.viewID, (int)messType);
         }
         //DebugConsole.LogWarning( "Done sending message to client." );
     }
     else
     {
         DebugConsole.LogWarning("Did not send client mess, because I AM A CLIENT.");
     }
 }
Example #2
0
 //assumes we're connected
 public static void SendClientPairMessage(Pair<NetworkPlayer, NetworkPlayer> pr, NetworkClient.MessType_ToClient messType, params string[] args) {
     //TODO call the no arg version if args is empty or null
     if (args == null || args.Length == 0 || args[0] == null || args[0].Length == 0) {
         NetworkClient.Instance.SendClientMess(pr.First, messType);
         NetworkClient.Instance.SendClientMess(pr.Second, messType);
     } else {
         NetworkClient.Instance.SendClientMess(pr.First, messType, args);
         NetworkClient.Instance.SendClientMess(pr.Second, messType, args);
     }
 }
Example #3
0
	void FromServerWString( NetworkViewID viewID , int messType, string args )//, NetworkMessageInfo nmi
	{
		//DebugConsole.LogWarning( "Called the string param version of the rpc." );
		if( Network.isServer ) DebugConsole.LogError( "Oh noz, FromServer invoked on the server (bad)." );
		//if( Network.isClient ) DebugConsole.LogWarning( "FromServer invoked on client (good)." );
	
		string[] rayArgs = null;
		if( args == null )
			DebugConsole.LogWarning( "FromServer had null string arguments." );
		else
		{
			//DebugConsole.Log( "args - " + args );
			rayArgs = args.Split( new char[] {','} );
		}
		
		NetworkClient.MessType_ToClient castMess = (NetworkClient.MessType_ToClient) messType;

		GameStateClient.Instance.MessageFromServer( castMess, rayArgs );
	}
Example #4
0
    public void MessageFromServer(NetworkClient.MessType_ToClient messType, string[] args)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append("Player ").Append(Network.player).Append(" GameStateClient.MessageFromServer: ").Append(messType.ToString());
        sb.Append("\n");

        if (args != null && args.Length > 0)
        {
            sb.Append("args[] contains: ").Append(NetworkClient.RayToString(args, ","));
        }
        Debug.Log(sb.ToString()); DebugConsole.Log(sb.ToString());

        /*
         * NOTE! any message that needs instant reaction should have a "case ..." here;
         * otherwise, the "case default" is to throw the message in a queue
         * (the queue we're using is a NetworkMailbox; by default the queue length is unbounded!)
         */
        switch (messType)
        {
        case NetworkClient.MessType_ToClient.PlayerPairReady:
//			currState = StateEnum.PlayerPairReady;
//			bPlayerPairReady = true;
            break;

        case NetworkClient.MessType_ToClient.RelationsList:
//			relationList = new string[ args.Length / 2 ];
//			mRelationToID = new SortedList<string, int>();
//			for( int i=0; i<args.Length; i = i + 2 )
//			{
//				mRelationToID.Add( args[i+1], Convert.ToInt32( args[i] ) );
//				relationList[ i / 2 ] = args[i+1];
//			}
            break;

        case NetworkClient.MessType_ToClient.DomainDescription:
            //toSend.Append( domainid ).Append( "|||" ).Append( domainName ).Append( "|||" ).Append( domainDescr );
//			if( args != null && args.Length > 0 )
//			{
//				string[] splitRay = Regex.Split( args[0],  Regex.Escape("|||") );
//				if( splitRay != null && splitRay.Length >= 2 && splitRay[ 1 ].Length > 0 )
//				{
//					domainid = Convert.ToInt32( splitRay[0] );
//					domainName = splitRay[1];
//					domainDescr = splitRay[2];
//				}else{
//					Debug.LogError( "Did not get domain description information!" );
//					NetworkClient.Instance.SendServerMess( NetworkClient.MessType_ToServer.PlayerHasNoLives );
//					DoGameOver( "Did not get domain description information!" );
//				}
//
//			}
//			else{
//				Debug.LogWarning( "GameStateClient.MessageFromServer: DomainDescription came back without ANY args." );
//				NetworkClient.Instance.SendServerMess( NetworkClient.MessType_ToServer.PlayerHasNoLives );
//				DoGameOver( "Did not get domain description information!" );
//			}
            break;

        case NetworkClient.MessType_ToClient.DomainObjectsInitial:
//			currState = StateEnum.PlayerPairReady;
//			domainObjects = new string[ args.Length / 2 ];//domainObjects = (string[])args.Clone();
//			mStoryObjectToID = new SortedList<string, int>();
//			for( int i=0; i<args.Length; i = i + 2 )
//			{
//				mStoryObjectToID.Add( args[i+1], Convert.ToInt32( args[i] ) );
//				mObjectidToObjectname.Add( args[i], args[i+1] );
//				domainObjects[ i / 2 ] = args[i+1];
//			}
//			Debug.Log( "GameStateClient.DomainObjectsInitial: " + NetworkClient.RayToString( args, "," ) );
            break;

        case NetworkClient.MessType_ToClient.DomainObjectsFinal:

//			if( args != null && args.Length > 0 )
//			{
//				Debug.Log( "GameStateClient.DomainObjectsFinal" );
//			    string[] tmpAgreed = args[0].Split( new char[] {'|'} );
//				if( tmpAgreed != null && tmpAgreed.Length > 0 && tmpAgreed[ 0 ].Length > 0 )
//				{
//					strAgreedObjDeleted = new string[ tmpAgreed.Length ];
//					for( int i=0; i<tmpAgreed.Length; i++ )//&& tmpAgreed[i] != null && tmpAgreed[i].Length > 0
//					{
//						if( mObjectidToObjectname.ContainsKey( tmpAgreed[ i ] ) )
//							strAgreedObjDeleted[ i ] = this.mObjectidToObjectname[ tmpAgreed[ i ] ];
//						else
//							Debug.LogWarning( "Didn't find deleted object id: " + tmpAgreed[i] );
//					}
//				}else
//					strAgreedObjDeleted = new string[ 0 ];
//
//
//				Debug.Log( "Got agreed deletes: " );
//				Debug.Log( NetworkClient.RayToString( strAgreedObjDeleted, "," ) );
//
//				tmpAgreed = args[1].Split( new char[] {'|'} );
//				if( tmpAgreed != null && tmpAgreed.Length > 0 && tmpAgreed[ 0 ].Length > 0 )
//				{
//					strAgreedObjNOTDeleted = new string[ tmpAgreed.Length ];
//					for( int i=0; i<tmpAgreed.Length; i++ )
//					{
//						if( mObjectidToObjectname.ContainsKey( tmpAgreed[ i ] ) )
//							strAgreedObjNOTDeleted[ i ] = this.mObjectidToObjectname[ tmpAgreed[ i ] ];
//						else
//							Debug.LogWarning( "Didn't find NON deleted object id: " + tmpAgreed[i] );
//					}
//				}else
//					strAgreedObjNOTDeleted = new string[ 0 ];
//
//				Debug.Log( "Got agreed NON deletes: " );
//				Debug.Log( NetworkClient.RayToString( strAgreedObjNOTDeleted, "," ) );
//
//				strAgreedObjAdded = args[2].Split( new char[] {'|'} );
//				if( strAgreedObjAdded != null && strAgreedObjAdded.Length > 0 && strAgreedObjAdded[ 0 ].Length > 0 )
//				{}
//				else
//					strAgreedObjAdded = new string[ 0 ];
//
//				Debug.Log( "Got agreed adds: " );
//				Debug.Log( NetworkClient.RayToString( strAgreedObjAdded, "," ) );
//			}
//			else{
//				Debug.LogWarning( "GameStateClient.MessageFromServer: Domain objects final came back without ANY args." );
//			}
            break;

        case NetworkClient.MessType_ToClient.NewDomainObjPair:

//			if( args != null && args.Length >=5 )
//			{
//				pairDomainObj = new Pair<string, string>( args[2], args[4] );
//				idPairDomainObj = Convert.ToInt32( args[0] );
//				currState = StateEnum.ChoosingLocalRelation;
//			}else{
//				Debug.LogWarning( "GameStateClient.MessageFromServer: NewDomainObjPair came back without ANY args." );
//			}
            break;

        case NetworkClient.MessType_ToClient.FirstToSelectRelation:
//			wasFirstToSelectRelation = true;
            break;

        case NetworkClient.MessType_ToClient.SwanReadyToMove:
//			millisecChoosingRelation = (System.DateTime.Now.Ticks / System.TimeSpan.TicksPerMillisecond); //record start time of selection
//			currState = StateEnum.SwanReadyToMove;
            break;

        case NetworkClient.MessType_ToClient.RelationMatchResult:
//			if( args != null && args.Length > 0 )
//			{
//				didLastRelationPairAgree = args[ 0 ].Equals( "agree", StringComparison.OrdinalIgnoreCase );
//				Debug.Log( "args[ 0 ].Equals( \"agree\", StringComparison.OrdinalIgnoreCase ) == " + didLastRelationPairAgree );
//			}
//			else
//				Debug.LogWarning( "GameStateClient.MessageFromServer: RelationMatchResult came back without ANY args." );
            break;

        case NetworkClient.MessType_ToClient.GameOver:
//			if( args != null && args.Length > 0 && args[0] != null)
//			{
//				DoGameOver( args[0] );
//			}
//			else
//			{
//				Debug.LogWarning( "GameStateClient.MessageFromServer: Got a game over message without any argument XD" );
//				DoGameOver( "" );
//			}
            break;

        case NetworkClient.MessType_ToClient.YouWin:
//			bAmWinner = true;
            break;

        default:
            DebugConsole.Log("MessageFromServer: default (adding to mailbox)");
            mailbox.AddMessage(messType, args);
            break;
        }
    }