コード例 #1
0
    public static List <string> SelectRandomTagSet(ScoringMode scoringMode)
    {
        List <string> tagSet = DBGWAPLoader.GenerateRandomTagset();

        if (scoringMode == ScoringMode.Both)
        {
            string lastTag = tagSet[tagSet.Count - 1];
            tagSet[tagSet.Count - 1] = lastTag + "-compete";
            tagSet.Add(lastTag + "-collab");
        }
        return(tagSet);
    }
コード例 #2
0
ファイル: GameStateServer.cs プロジェクト: zookae/Microgames
    //THIS IS THE KEY METHOD OF THIS CLASS
    public void MessageFromClient(NetworkPlayer player, NetworkClient.MessType_ToServer messType, string args)
    {
        DebugConsole.LogWarning("GameStateServer.MessageFromClient " + player + ": " + messType.ToString());
        DebugConsole.Log("args: ");
        if (args == null || args.Length == 0)
        {
            DebugConsole.Log("<null or zero length>");
        }
        else
        {
            DebugConsole.Log(args);
        }

        //if( args != null && args.Length > 0 ) DebugConsole.Log( NetworkClient.RayToString( args ) );
        RunningGameData rgd = getRunningGameData(player, messType, args);

        if (rgd == null)
        {
            return;             //this is ok.
        }
        DebugConsole.Log("Hitting big message demux.");

        switch (messType)
        {
        //TODO case NetworkClient.MessType_ToServer.ReadDBStr:  "udid" arg
        case NetworkClient.MessType_ToServer.ReadDBStr:
            if (String.Compare("udid", args, true) == 0)
            {
                NetworkClient.Instance.SendClientMess(player, NetworkClient.MessType_ToClient.UNTYPED, dbManip.getPlayerUDID(rgd.dPlayerData[player].playerid));
            }
            break;

        case NetworkClient.MessType_ToServer.SaveDBStr:
            DebugConsole.Log("client requested save string : " + args);
            dbManip.dataDump(rgd.gameID, rgd.dPlayerData[player].playerid, args);
            DebugConsole.Log("dumped string info : " + rgd.gameID + ", " + rgd.dPlayerData[player].playerid + ", " + args);
            break;

        case NetworkClient.MessType_ToServer.DomainObjectIDsDeleted:
//			rgd.Mess_DomainObjectIDsDeleted( player, args );
//			rgd.SendFinalListAndFirstPairWhenReady( player );
            break;

        case NetworkClient.MessType_ToServer.DomainObjectIDsNOTDeleted:
//			rgd.Mess_DomainObjectIDsNOTDeleted( player, args );
//			rgd.SendFinalListAndFirstPairWhenReady( player );
            break;

        case NetworkClient.MessType_ToServer.DomainObjectNamesAdded:
//			rgd.Mess_DomainObjectNamesAdded( player, args );
//			rgd.SendFinalListAndFirstPairWhenReady( player );
            break;

        case NetworkClient.MessType_ToServer.JustGotToSwanScreen:         //has playerScore arg; for when we're not doing add/remove objects screen
//			rgd.Mess_JustGotToSwanScreen( player, args );
            break;

        case NetworkClient.MessType_ToServer.SelectedRelation:
            //DebugConsole.Log( "MessageFromClient: MessType.SelectedRelation" );
//			rgd.Mess_SelectedRelation( player, args );
            break;

        case NetworkClient.MessType_ToServer.SwanAtEndOfScreen:         //has playerScore, millisec args
//			rgd.Mess_SwanAtEndOfScreen( player, args );
            break;

        case NetworkClient.MessType_ToServer.PlayerHasNoLives:         //has playerScore arg
//			rgd.Mess_PlayerHasNoLives( player, args );
            break;

        case NetworkClient.MessType_ToServer.PlayAgain:         //HANDLED IN getRunningGameData
            //PlayerConnected( player );
//			NetworkClient.Instance.SendClientMess( player, NetworkClient.MessType_ToClient.RelationsList, strListRelations );

            //select, send the domain
//			System.Collections.Generic.KeyValuePair<int,System.Text.StringBuilder> ansPair = rgd.SelectDomainid();
//			if( ansPair.Equals( default(KeyValuePair<int,System.Text.StringBuilder>) ) )
//			{	//no more domains to work on!
//				rgd.EndGame( "No more domains to play!", null );
//			}else{
//				rgd.ResetVarsForNewGame();
//				rgd.domainID = ansPair.Key;
//				NetworkClient.Instance.SendClientMess( player, NetworkClient.MessType_ToClient.DomainDescription, ansPair.Value.ToString() );
//				NetworkClient.Instance.SendClientMess( player, NetworkClient.MessType_ToClient.PlayerPairReady );
//			}
            break;

        case NetworkClient.MessType_ToServer.DeviceUniqueIdentifier: //may be HANDLED IN getRunningGameData
            rgd.SetUniqueDeviceID(player, args);                     //comes from NetworkClient.OnConnectedToServer
            DebugConsole.Log("Got a UDID of: " + args);
            break;

        // UNIQUE AND SPECIFIC TO SNG ONLY
        // Whenever we want to create a new game, we do this.
        case NetworkClient.MessType_ToServer.SNGRequestNewGame:
            int gameId = dbManip.SaveGameBasics(dbManip.getPlayerUDID(rgd.dPlayerData[player].playerid));
            rgd.gameID = gameId;
            dbManip.SaveGameType(rgd.gameID, rgd.gameMode);

            List <string> objectSet = DBGWAPLoader.GenerateRandomObjectSet(7);
            List <string> tagSet    = DBGWAPLoader.GenerateRandomTagset();
            rgd.objectSet = objectSet;
            rgd.tagSet    = tagSet;

            // Sends the game mode
            NetworkClient.Instance.SendClientMess(player, NetworkClient.MessType_ToClient.SNGGameMode, rgd.gameMode.ToString());

            // Construct the object and tag sets.
            if (objectSet != null)
            {
                NetworkClient.Instance.SendClientMess(player, NetworkClient.MessType_ToClient.SNGObjectSet, DBStringHelper.listToString(objectSet, ','));
            }
            if (tagSet != null)
            {
                if (rgd.gameMode == 3)
                {
                    List <string> modifiedTagSet = new List <string>(tagSet);
                    modifiedTagSet[1] = tagSet[1] + "-compete";
                    modifiedTagSet.Add(tagSet[1] + "-collab");
                    NetworkClient.Instance.SendClientMess(player, NetworkClient.MessType_ToClient.SNGTagSet, DBStringHelper.listToString(modifiedTagSet, ','));
                }
                else
                {
                    NetworkClient.Instance.SendClientMess(player, NetworkClient.MessType_ToClient.SNGTagSet, DBStringHelper.listToString(tagSet, ','));
                }
            }

            int gamemode = dbManip.LookupPlayerGametype(rgd.dPlayerData[player].playerid);
            DebugConsole.Log("Game mode found = " + gamemode);
            if (gamemode == -1)
            {
                DebugConsole.Log("Need to add a new player.");
                dbManip.SavePlayerGameType(rgd.dPlayerData[player].playerid, rgd.gameMode);
            }

            break;

        case NetworkClient.MessType_ToServer.SNGRequestGameMode:
            if (rgd.gameMode == -1)
            {
                int gt = dbManip.LookupPlayerGametype(rgd.dPlayerData[player].playerid);
                if (gt != -1)
                {
                    DebugConsole.Log("Found an old player. Their gametype is : " + gt);
                    rgd.gameMode = gt;
                }
                else
                {
                    rgd.gameMode = UnityEngine.Random.Range(1, 4);
                    DebugConsole.Log("Found a new player! Assigning a random gametype of " + rgd.gameMode);
                    dbManip.SavePlayerGameType(rgd.dPlayerData[player].playerid, rgd.gameMode);
                }
            }
            NetworkClient.Instance.SendClientMess(player, NetworkClient.MessType_ToClient.SNGGameMode, rgd.gameMode.ToString());
            break;

        case NetworkClient.MessType_ToServer.SNGRequestTrace:
            // (OH GOD BAD HARDCODED NUMBERS)
            string[] times = (dbManip.LookupRandomTraces(1, 1))[0].Split(',');
            DebugConsole.Log("Got a random timing thing from the database.");

            // Construct and send the partner trace.
            List <Triple <double, string, string> > partnerTrace;
            if (rgd.gameMode == 3)   // BOTH MODE
            {
                List <string> opponentTrace = new List <string>();
                opponentTrace.Add(rgd.tagSet[1]);
                opponentTrace.Add(rgd.tagSet[0] + "-compete");
                opponentTrace.Add(rgd.tagSet[0] + "-collab");
                partnerTrace = DBGWAPLoader.ConstructRandomPartnerTrace(times, rgd.objectSet, opponentTrace);
            }
            else
            {
                partnerTrace = DBGWAPLoader.ConstructRandomPartnerTrace(times, rgd.objectSet, rgd.tagSet);
            }

            if (partnerTrace != null)
            {
                NetworkClient.Instance.SendClientMess(player, NetworkClient.MessType_ToClient.SNGOpponentTrace, DBStringHelper.traceToString(partnerTrace, ':'));
                DebugConsole.Log("SENT A TRACE!");
            }
            else
            {
                DebugConsole.Log("DIDN'T SEND TRACE!");
            }
            break;

        case NetworkClient.MessType_ToServer.SNGSaveDBTrace:
            DebugConsole.Log("Got a trace from a player.");
            string[] traces = args.Split(',');
            // This is a really awful hack...someone just kill me please.
            // Basically, if I want to reuse all of my string helper functions, I have to manhandle some strings.
            // THIS IS WHY THE CLIENT SHOULDN'T AUTOSPLIT STRINGS WHEN READING FROM THE SERVER DAMMIT.
            // YOUR LOGIC IS NOT TWO-WAY...RANT...RANT...RAAAAAAAAAAAAAANT.
            for (int i = 0; i < traces.Length; i++)
            {
                traces[i] = traces[i].Replace(':', ',');
            }
            if (traces.Length != 3)
            {
                DebugConsole.Log("Ill-formed trace info.");
                break;
            }
            dbManip.SaveTraceResults(rgd.gameID, 1, traces[0]);
            dbManip.SaveTraceResults(rgd.gameID, 2, traces[1]);
            dbManip.SaveTraceResults(rgd.gameID, 3, traces[2]);
            string objSetStr = DBStringHelper.listToString(rgd.objectSet, ',');
            string tagSetStr = DBStringHelper.listToString(rgd.tagSet, ',');
            // XXX (kasiu): Need to save score properly
            dbManip.SaveGameGwapData(rgd.gameID, 0, rgd.dPlayerData[player].playerid, objSetStr, tagSetStr);
            // Increment player score:
            dbManip.IncrementPlayerGameCount(rgd.dPlayerData[player].playerid);
            break;

        case NetworkClient.MessType_ToServer.SNGSavePlayerData:
            // used for SNG only
            int gametype = dbManip.LookupPlayerGametype(rgd.dPlayerData[player].playerid);
            if (gametype != -1)
            {
                DebugConsole.Log("Found an old player. Their gametype is : " + gametype);
                rgd.gameMode = gametype;
            }
            else
            {
                rgd.gameMode = UnityEngine.Random.Range(1, 4);
                DebugConsole.Log("Found a new player! Assigning a random gametype of " + rgd.gameMode);
                dbManip.SavePlayerGameType(rgd.dPlayerData[player].playerid, rgd.gameMode);
                //dbManip.SavePlayerInformation(dbManip.getPlayerUDID(rgd.dPlayerData[player].playerid), rgd.gameMode);
            }
            break;

        case NetworkClient.MessType_ToServer.SNGSavePlayerLikertData:
            DebugConsole.Log("Got some survey data! We'll be saving this!");
            string[] answers = args.Split(':');
            dbManip.SavePlayerLikertScores(rgd.dPlayerData[player].playerid, answers);
            break;

        case NetworkClient.MessType_ToServer.SNGSavePlayerScore:
            dbManip.SaveGameScore(rgd.gameID, System.Convert.ToInt32(args));
            break;

        /*
         * BULLETHELL CODE
         */
        case NetworkClient.MessType_ToServer.BHSaveParamTrace:
            DebugConsole.Log("Got a trace from a player.");
            dbManip.SaveTraceResults(rgd.gameID, 4, args); // trace type 4 = bullethell parameter tuning trace
            // Increment player score:
            dbManip.IncrementPlayerBHDesignCount(rgd.dPlayerData[player].playerid);
            break;

        default:
            DebugConsole.Log("MessageFromClient: default");
            break;
        }
    }