Example #1
0
/**	文字列入力
 *	@param		cnsl	コンソール
 *	@param[out]	rcvbf	入力文字
 *	@param		len		入力文字数
 *	@return 			実際の入力文字数(エラー時マイナス値)
 ****************************************************************************** */
int		TELNET_Read( CONSOLE *cnsl, UB *rcvbf, int len )
{
static const UB TelnetNegotiationTbl[] =
{
	TELNET_COMMAND_IAC, TELNET_COMMAND_WILL, TELNET_OPTION_SUPPRESS_GA,
	TELNET_COMMAND_IAC, TELNET_COMMAND_WILL, TELNET_OPTION_ECHO,
	TELNET_COMMAND_IAC, TELNET_COMMAND_DONT, TELNET_OPTION_ECHO
};
UB	dt;
BOOL	negofg = FALSE;
int	rcvlen = 0;
int	retval = -1;

	if( !((TELNET_PARA*)cnsl->Parameter)->OpenFg )
		goto EXIT;

	for( rcvlen = 0; rcvlen < len; )
	{
		if( !TELNET_GetByte( cnsl, &dt ) )	/* データ取り込み	*/
			goto EXIT;
		if( dt == TELNET_NOP )
			continue;	/* 前のデータがCRだった場合、0x00 が受信される	*/

		if( dt == TELNET_COMMAND_IAC )
		{	/* ネゴシエーション */
			if( !negofg )
			{
				if( TELNET_Write( cnsl, TelnetNegotiationTbl, sizeof( TelnetNegotiationTbl ) ) < 0 )
					goto EXIT;
				negofg = TRUE;
			}
			if( !TELNET_GetByte( cnsl, &dt ) )
				goto EXIT;
			if( !TELNET_GetByte( cnsl, &dt ) )
				goto EXIT;
		}
		else
		{
			rcvbf[ rcvlen++ ] = dt;
		}
	}
	retval = rcvlen;

EXIT:;
	return retval;
}
Example #2
0
void GROUP_Group (int nRound, char *cS)
    {
    char cCmd [255], cGrp [255], cH1 [255], cH2 [255], cH3 [255], cH4 [255] ;
    char cGarbage [4096] ;
    int  nH1, nH2, nH3, nH4 ;

    int  nN, nG, nI, nJ, nR ;
    int  aG [4] ;

    int  nC, nU, nP, bFound ;
    int  aP [4] ;

    strcpy (cCmd, "") ;
    strcpy (cGrp, "") ;
    strcpy (cH1,  "") ;
    strcpy (cH2,  "") ;
    strcpy (cH3,  "") ;
    strcpy (cH4,  "") ;

    sscanf (cS, "%s %s %s %s %s %s", &cCmd, &cGrp, &cH1, &cH2, &cH3, &cH4) ;

    switch (nPlayer)
        {
        case 8 :
            if (nRound == 0)
                {
                if ((strcmp (cGrp, "1") != 0) &&
                    (strcmp (cGrp, "2") != 0))
                    {
                    sprintf (cGarbage, "%s %s Valid group #s are 1 or 2\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return ;
                    }
                }
            else
                {
                if (strcmp (cGrp, "1") != 0)
                    {
                    sprintf (cGarbage, "%s %s Valid group # is 1\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return ;
                    }
                }
            break ;

        case 12 :
            if (nRound == 0)
                {
                if ((strcmp (cGrp, "1") != 0) &&
                    (strcmp (cGrp, "2") != 0) &&
                    (strcmp (cGrp, "3") != 0))
                    {
                    sprintf (cGarbage, "%s %s Valid group #s are 1, 2, or 3\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return ;
                    }
                }
            else
            if (nRound == 1)
                {
                if ((strcmp (cGrp, "1") != 0) &&
                    (strcmp (cGrp, "2") != 0))
                    {
                    sprintf (cGarbage, "%s %s Valid group #s are 1 or 2\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return ;
                    }
                }
            else
                {
                if (strcmp (cGrp, "1") != 0)
                    {
                    sprintf (cGarbage, "%s %s Valid group # is 1\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return ;
                    }
                }
            break ;

        case 16 :
            if (nRound == 0)
                {
                if ((strcmp (cGrp, "1") != 0) &&
                    (strcmp (cGrp, "2") != 0) &&
                    (strcmp (cGrp, "3") != 0) &&
                    (strcmp (cGrp, "4") != 0))
                    {
                    sprintf (cGarbage, "%s %s Valid group #s are 1, 2, 3, or 4\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return ;
                    }
                }
            else
            if (nRound == 1)
                {
                if ((strcmp (cGrp, "1") != 0) &&
                    (strcmp (cGrp, "2") != 0))
                    {
                    sprintf (cGarbage, "%s %s Valid group #s are 1 or 2\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return ;
                    }
                }
            else
                {
                if (strcmp (cGrp, "1") != 0)
                    {
                    sprintf (cGarbage, "%s %s Valid group # is 1\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return ;
                    }
                }
            break ;
        }

    if (strlen (cH1) == 0)
        {
        sprintf (cGarbage, "%s %s Missing handle #1\n", ICS_TELL, cArbiter) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }

    if (! PLAYER_FindUpperCasePlayer (cH1, &nH1))
        {
        sprintf (cGarbage, "%s %s %s is not in the tourney\n", ICS_TELL, cArbiter, cH1) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }
        
    if (strlen (cH2) == 0)
        {
        sprintf (cGarbage, "%s %s Missing handle #2\n", ICS_TELL, cArbiter) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }

    if (! PLAYER_FindUpperCasePlayer (cH2, &nH2))
        {
        sprintf (cGarbage, "%s %s %s is not in the tourney\n", ICS_TELL, cArbiter, cH2) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }

    if (nH2 == nH1)
        {
        sprintf (cGarbage, "%s %s %s can only appear once in the group\n", ICS_TELL, cArbiter, cH2) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }

    if (strlen (cH3) == 0)
        {
        sprintf (cGarbage, "%s %s Missing handle #3\n", ICS_TELL, cArbiter) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }

    if (! PLAYER_FindUpperCasePlayer (cH3, &nH3))
        {
        sprintf (cGarbage, "%s %s %s is not in the tourney\n", ICS_TELL, cArbiter, cH3) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }

    if ((nH3 == nH1) || (nH3 == nH2))
        {
        sprintf (cGarbage, "%s %s %s can only appear once in the group\n", ICS_TELL, cArbiter, cH3) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }

    if (strlen (cH4) == 0)
        {
        sprintf (cGarbage, "%s %s Missing handle #4\n", ICS_TELL, cArbiter) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }

    if (! PLAYER_FindUpperCasePlayer (cH4, &nH4))
        {
        sprintf (cGarbage, "%s %s %s is not in the tourney\n", ICS_TELL, cArbiter, cH4) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }

    if ((nH4 == nH1) || (nH4 == nH2) || (nH4 == nH3))
        {
        sprintf (cGarbage, "%s %s %s can only appear once in the group\n", ICS_TELL, cArbiter, cH4) ;

        TIMESEAL_Write (cGarbage) ;
        TELNET_Write   (cGarbage) ;
        return ;
        }

    if (strcmp (cGrp, "1") == 0)
        {
        nN = 0 ;
        }
    else
    if (strcmp (cGrp, "2") == 0)
        {
        nN = 1 ;
        }
    else
    if (strcmp (cGrp, "3") == 0)
        {
        nN = 2 ;
        }
    else
    if (strcmp (cGrp, "4") == 0)
        {
        nN = 3 ;
        }

    for (nG = 0 ; nG < nGroup [nRound] ; nG++)
        {
        for (nI = 0 ; nI < MAX_GROUP_MEMBER ; nI++)
            {
            if ((aGroup [nRound] [nG] [nI] == nH1) ||
                (aGroup [nRound] [nG] [nI] == nH2) ||
                (aGroup [nRound] [nG] [nI] == nH3) ||
                (aGroup [nRound] [nG] [nI] == nH4))
                {
                aGroup [nRound] [nG] [0] = 0 ;
                aGroup [nRound] [nG] [1] = 0 ;
                aGroup [nRound] [nG] [2] = 0 ;
                aGroup [nRound] [nG] [3] = 0 ;
                break ;
                }
            }
        }

    aGroup [nRound] [nN] [0] = nH1 ;
    aGroup [nRound] [nN] [1] = nH2 ;
    aGroup [nRound] [nN] [2] = nH3 ;
    aGroup [nRound] [nN] [3] = nH4 ;

    if (nPlayer == 8)
        {
        if (nN == 0)
            {
            nR = 1 ;
            }
        else
            {
            nR = 0 ;
            }

        nJ = 0 ;
        for (nI = 0 ; nI < 8 ; nI++)
            {
            if ((nI != nH1) && (nI != nH2) && (nI != nH3) && (nI != nH4))
                {
                aG [nJ] = nI ;
                nJ = nJ + 1 ;
                }
            }

        aGroup [nRound] [nR] [0] = aG [0] ;
        aGroup [nRound] [nR] [1] = aG [1] ;
        aGroup [nRound] [nR] [2] = aG [2] ;
        aGroup [nRound] [nR] [3] = aG [3] ;
        }
    else
        {
        nC = 0 ;

        for (nG = 0 ; nG < nGroup [nRound] ; nG++)
            {
            if ((aGroup [nRound] [nG] [0] == 0) &&
                (aGroup [nRound] [nG] [1] == 0) &&
                (aGroup [nRound] [nG] [2] == 0) &&
                (aGroup [nRound] [nG] [3] == 0))
                {
                // unused group
                }
            else
                {
                nC = nC + 1 ;
                }
            }

        if ((nC + 1) == nGroup [nRound])
            {
            nC = 0 ;
            nU = -1 ;

            for (nP = 0 ; nP < nPlayer ; nP++)
                {
                bFound = 0 ;

                for (nG = 0 ; nG < nGroup [nRound] ; nG++)
                    {
                    if ((aGroup [nRound] [nG] [0] == 0) &&
                        (aGroup [nRound] [nG] [1] == 0) &&
                        (aGroup [nRound] [nG] [2] == 0) &&
                        (aGroup [nRound] [nG] [3] == 0))
                        {
                        // unused group

                        if (nU == -1)
                            {
                            nU = nG ;
                            }
                        }
                    else
                        {
                        if ((aGroup [nRound] [nG] [0] == nP) ||
                            (aGroup [nRound] [nG] [1] == nP) ||
                            (aGroup [nRound] [nG] [2] == nP) ||
                            (aGroup [nRound] [nG] [3] == nP))
                            {
                            bFound = 1 ;
                            break ;
                            }
                        }
                    }

                if (! bFound)
                    {
                    if (nC < MAX_GROUP_MEMBER)
                        {
                        aP [nC] = nP ;
                        nC = nC + 1 ;
                        }
                    }
                }

            if (nU != -1)
                {
                if (nC == MAX_GROUP_MEMBER)
                    {
                    aGroup [nRound] [nU] [0] = aP [0] ;
                    aGroup [nRound] [nU] [1] = aP [1] ;
                    aGroup [nRound] [nU] [2] = aP [2] ;
                    aGroup [nRound] [nU] [3] = aP [3] ;
                    }
                }
            }
        }

    sprintf (cGarbage, "SHOWGROUP %d", nN + 1) ;

    GROUP_Show (nRound, cGarbage, 1, 0) ;

    GROUP_Write (nRound) ;
    }
Example #3
0
void GROUP_Post (int nRound, char *cS)
    {
    char cTmp [4096], cGarbage [4096] ;
    int  nC, nG, nP, bFound ;
    int  nZ ;

    nZ = GROUP_ValidGroup (nRound, cS) ;

    if (nZ == -1)
        {
        return ;
        }

    if (nZ == 0)
        {
        switch (nRound)
            {
            case 0 :
                sprintf (cTmp, "%s %d Round 1 Group\n", ICS_TELL, nChannel) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;

                sprintf (cTmp, "%s %d -------------\n", ICS_TELL, nChannel) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;
                break ;

            case 1 :
                sprintf (cTmp, "%s %d Semi-finals Group\n", ICS_TELL, nChannel) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;

                sprintf (cTmp, "%s %d -----------------\n", ICS_TELL, nChannel) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;
                break ;

            case 2 :
                sprintf (cTmp, "%s %d Final Round Group\n", ICS_TELL, nChannel) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;

                sprintf (cTmp, "%s %d -----------------\n", ICS_TELL, nChannel) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;
                break ;
            }
        }

    nC = 0 ;

    for (nG = 0 ; nG < nGroup [nRound] ; nG++)
        {
        if (nZ > 0)
            {
            if (nG != (nZ - 1))
                {
                continue ;
                }
            }

        if ((aGroup [nRound] [nG] [0] == 0) &&
            (aGroup [nRound] [nG] [1] == 0) &&
            (aGroup [nRound] [nG] [2] == 0) &&
            (aGroup [nRound] [nG] [3] == 0))
            {
            sprintf (cTmp,
                     "%s %d Group %d: (none)\n",
                     ICS_TELL,
                     nChannel,
                     nG + 1) ;
            }
        else
            {
            sprintf (cTmp,
                     "%s %d Group %d: %s %s %s %s\n",
                     ICS_TELL,
                     nChannel,
                     nG + 1,
                     Player [aGroup [nRound] [nG] [0]].cHandle,
                     Player [aGroup [nRound] [nG] [1]].cHandle,
                     Player [aGroup [nRound] [nG] [2]].cHandle,
                     Player [aGroup [nRound] [nG] [3]].cHandle) ;

            nC = nC + 1 ;
            }

        TIMESEAL_Write (cTmp) ;
        TELNET_Write   (cTmp) ;
        }

    if (nZ == 0)
        {
        if (nC != nGroup [nRound])
            {
            strcpy (cTmp, "") ;

            for (nP = 0 ; nP < nPlayer ; nP++)
                {
                bFound = 0 ;

                for (nG = 0 ; nG < nGroup [nRound] ; nG++)
                    {
                    if ((aGroup [nRound] [nG] [0] == 0) &&
                        (aGroup [nRound] [nG] [1] == 0) &&
                        (aGroup [nRound] [nG] [2] == 0) &&
                        (aGroup [nRound] [nG] [3] == 0))
                        {
                        // unused group
                        }
                    else
                        {
                        if ((aGroup [nRound] [nG] [0] == nP) ||
                            (aGroup [nRound] [nG] [1] == nP) ||
                            (aGroup [nRound] [nG] [2] == nP) ||
                            (aGroup [nRound] [nG] [3] == nP))
                            {
                            bFound = 1 ;
                            break ;
                            }
                        }
                    }

                if (! bFound)
                    {
                    if (strlen (cTmp) == 0)
                        {
                        strcpy (cTmp, Player [nP].cHandle) ;
                        }
                    else
                        {
                        strcat (cTmp, ", ") ;
                        strcat (cTmp, Player [nP].cHandle) ;
                        }
                    }
                }

            if (strlen (cTmp) > 0)
                {
                sprintf (cGarbage, "%s %d Ungrouped players: %s\n", ICS_TELL, nChannel, cTmp) ;

                TIMESEAL_Write (cGarbage) ;
                TELNET_Write   (cGarbage) ;
                }
            }
        }
    }
Example #4
0
void GROUP_Show (int nRound, char *cS, int bArbiter, int nPG)
    {
    char cTarget [4096], cTmp [4096], cGarbage [4096] ;
    int  nC, nG, nP, bFound ;
    int  nZ ;

    if (bArbiter == 1)
        {
        nZ = GROUP_ValidGroup (nRound, cS) ;

        if (nZ == -1)
            {
            return ;
            }

        strcpy (cTarget, cArbiter) ;
        }
    else
    if (bArbiter == 2)
        {
        nZ = 0 ;

        strcpy (cTarget, cWatcher) ;
        }
    else
    if (bArbiter == 3)
        {
        strcpy (cTarget, cArb) ;

        nZ = nPG + 1 ;
        }
    else
        {
        strcpy (cTarget, cPlayer) ;

        nZ = nPG + 1 ;
        }

    if (nZ == 0)
        {
        switch (nRound)
            {
            case 0 :
                sprintf (cTmp, "%s %s Round 1 Group\n", ICS_TELL, cTarget) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;

                sprintf (cTmp, "%s %s -------------\n", ICS_TELL, cTarget) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;
                break ;

            case 1 :
                sprintf (cTmp, "%s %s Semi-finals Group\n", ICS_TELL, cTarget) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;

                sprintf (cTmp, "%s %s -----------------\n", ICS_TELL, cTarget) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;
                break ;

            case 2 :
                sprintf (cTmp, "%s %s Final Round Group\n", ICS_TELL, cTarget) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;

                sprintf (cTmp, "%s %s -----------------\n", ICS_TELL, cTarget) ;

                TIMESEAL_Write (cTmp) ;
                TELNET_Write   (cTmp) ;
                break ;
            }
        }

    nC = 0 ;

    for (nG = 0 ; nG < nGroup [nRound] ; nG++)
        {
        if (nZ > 0)
            {
            if (nG != (nZ - 1))
                {
                continue ;
                }
            }

        if ((aGroup [nRound] [nG] [0] == 0) &&
            (aGroup [nRound] [nG] [1] == 0) &&
            (aGroup [nRound] [nG] [2] == 0) &&
            (aGroup [nRound] [nG] [3] == 0))
            {
            sprintf (cTmp,
                     "%s %s Group %d: (none)\n",
                     ICS_TELL,
                     cTarget,
                     nG + 1) ;
            }
        else
            {
            sprintf (cTmp,
                     "%s %s Group %d: %s %s %s %s\n",
                     ICS_TELL,
                     cTarget,
                     nG + 1,
                     Player [aGroup [nRound] [nG] [0]].cHandle,
                     Player [aGroup [nRound] [nG] [1]].cHandle,
                     Player [aGroup [nRound] [nG] [2]].cHandle,
                     Player [aGroup [nRound] [nG] [3]].cHandle) ;

            nC = nC + 1 ;
            }

        TIMESEAL_Write (cTmp) ;
        TELNET_Write   (cTmp) ;
        }

    if (nZ == 0)
        {
        if (nC != nGroup [nRound])
            {
            strcpy (cTmp, "") ;

            for (nP = 0 ; nP < nPlayer ; nP++)
                {
                bFound = 0 ;

                for (nG = 0 ; nG < nGroup [nRound] ; nG++)
                    {
                    if ((aGroup [nRound] [nG] [0] == 0) &&
                        (aGroup [nRound] [nG] [1] == 0) &&
                        (aGroup [nRound] [nG] [2] == 0) &&
                        (aGroup [nRound] [nG] [3] == 0))
                        {
                        // unused group
                        }
                    else
                        {
                        if ((aGroup [nRound] [nG] [0] == nP) ||
                            (aGroup [nRound] [nG] [1] == nP) ||
                            (aGroup [nRound] [nG] [2] == nP) ||
                            (aGroup [nRound] [nG] [3] == nP))
                            {
                            bFound = 1 ;
                            break ;
                            }
                        }
                    }

                if (! bFound)
                    {
                    if (strlen (cTmp) == 0)
                        {
                        strcpy (cTmp, Player [nP].cHandle) ;
                        }
                    else
                        {
                        strcat (cTmp, ", ") ;
                        strcat (cTmp, Player [nP].cHandle) ;
                        }
                    }
                }

            if (strlen (cTmp) > 0)
                {
                sprintf (cGarbage, "%s %s Ungrouped players: %s\n", ICS_TELL, cTarget, cTmp) ;

                TIMESEAL_Write (cGarbage) ;
                TELNET_Write   (cGarbage) ;
                }
            }
        }
    }
Example #5
0
int GROUP_ValidGroup (int nRound, char *cS)
    {
    char cCmd [4096], cGrp [4096], cGarbage [4096] ;

    strcpy (cCmd, "") ;
    strcpy (cGrp, "") ;

    sscanf (cS, "%s %s", &cCmd, &cGrp) ;

    if (strlen (cGrp) == 0)
        {
        return 0 ;
        }

    switch (nPlayer)
        {
        case 8 :
            if (nRound == 0)
                {
                if ((strcmp (cGrp, "1") != 0) &&
                    (strcmp (cGrp, "2") != 0))
                    {
                    sprintf (cGarbage, "%s %s Valid group #s are 1 or 2\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return -1 ;
                    }
                }
            else
                {
                if (strcmp (cGrp, "1") != 0)
                    {
                    sprintf (cGarbage, "%s %s Valid group # is 1\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return -1 ;
                    }
                }
            break ;

        case 12 :
            if (nRound == 0)
                {
                if ((strcmp (cGrp, "1") != 0) &&
                    (strcmp (cGrp, "2") != 0) &&
                    (strcmp (cGrp, "3") != 0))
                    {
                    sprintf (cGarbage, "%s %s Valid group #s are 1, 2, or 3\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return -1 ;
                    }
                }
            else
            if (nRound == 1)
                {
                if ((strcmp (cGrp, "1") != 0) &&
                    (strcmp (cGrp, "2") != 0))
                    {
                    sprintf (cGarbage, "%s %s Valid group #s are 1 or 2\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return -1 ;
                    }
                }
            else
                {
                if (strcmp (cGrp, "1") != 0)
                    {
                    sprintf (cGarbage, "%s %s Valid group # is 1\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return -1 ;
                    }
                }
            break ;

        case 16 :
            if (nRound == 0)
                {
                if ((strcmp (cGrp, "1") != 0) &&
                    (strcmp (cGrp, "2") != 0) &&
                    (strcmp (cGrp, "3") != 0) &&
                    (strcmp (cGrp, "4") != 0))
                    {
                    sprintf (cGarbage, "%s %s Valid group #s are 1, 2, 3, or 4\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return -1 ;
                    }
                }
            else
            if (nRound == 1)
                {
                if ((strcmp (cGrp, "1") != 0) &&
                    (strcmp (cGrp, "2") != 0))
                    {
                    sprintf (cGarbage, "%s %s Valid group #s are 1 or 2\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return -1 ;
                    }
                }
            else
                {
                if (strcmp (cGrp, "1") != 0)
                    {
                    sprintf (cGarbage, "%s %s Valid group # is 1\n", ICS_TELL, cArbiter) ;

                    TIMESEAL_Write (cGarbage) ;
                    TELNET_Write   (cGarbage) ;
                    return -1 ;
                    }
                }
            break ;
        }

    if (strcmp (cGrp, "1") == 0)
        {
        return 1 ;
        }

    if (strcmp (cGrp, "2") == 0)
        {
        return 2 ;
        }

    if (strcmp (cGrp, "3") == 0)
        {
        return 3 ;
        }

    if (strcmp (cGrp, "4") == 0)
        {
        return 4 ;
        }

    return 0 ;
    }
Example #6
0
void GROUP_Write (int nRound)
    {
    FILE *Fv ;

    char Drive [_MAX_DRIVE] ;
    char Dir   [_MAX_DIR] ;
    char File  [_MAX_FNAME] ;
    char Ext   [_MAX_EXT] ;
    char Grp   [_MAX_PATH] ;

    char Tmp   [1024] ;
    int  nG ;

    // generate a full path GROUP1/2/3.TXT
    _splitpath (InstallDir, Drive, Dir, File, Ext) ;

    if (nRound == 0)
        {
        strcpy (File, GROUP1_NAME) ;
        }
    else
    if (nRound == 1)
        {
        strcpy (File, GROUP2_NAME) ;
        }
    else
        {
        strcpy (File, GROUP3_NAME) ;
        }

    strcpy (Ext, GROUP_EXT) ;

    _makepath (Grp, Drive, Dir, File, Ext) ;

    // open
    Fv = fopen (Grp, "w") ;
    if (Fv == NULL)
        {
        sprintf (Tmp, "\n || Writing %s failed\n\n", Grp) ;
        TELNET_Write (Tmp) ;
        return ;
        }

    fprintf (Fv, ";\n") ;
    fprintf (Fv, "; TBOT group file\n") ;
    fprintf (Fv, ";\n") ;

    // [Main]
    fprintf (Fv, "[Main]\n") ;

    // group
    fprintf (Fv, "Count=%d\n", nGroup [nRound]) ;

    for (nG = 0 ; nG < MAX_GROUP ; nG++)
        {
        fprintf (Fv, "\n[Group %d]\n", nG + 1) ;
        fprintf (Fv, "Index 1=%d\n", aGroup [nRound] [nG] [0]) ;
        fprintf (Fv, "Index 2=%d\n", aGroup [nRound] [nG] [1]) ;
        fprintf (Fv, "Index 3=%d\n", aGroup [nRound] [nG] [2]) ;
        fprintf (Fv, "Index 4=%d\n", aGroup [nRound] [nG] [3]) ;
        }

    // close
    fclose (Fv) ;
    }
Example #7
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
    {
    HDC         hdc ;
    PAINTSTRUCT ps ;
    RECT        rc ;
    HFONT       hfOld ;
    SIZE        szLine ;
    int         nH ;
    static int  nTimer = -1, nTimerCount = 0 ;
    char        *cStart, *cEnd, Tmp [512] ;

    switch (iMsg)
        {
        case WM_CREATE :

            // remember main window handle
            hwndMain = hwnd ;

            // install background color
            DeleteObject ((HBRUSH) SetClassLong (hwnd, GCL_HBRBACKGROUND,
                          (LONG) CreateSolidBrush (clrBackground))) ;

            // create text window
            hwndText = CreateWindow ("RICHEDIT", NULL,
                                     WS_CHILD | ES_MULTILINE | ES_READONLY |
                                     ES_NUMBER | WS_BORDER | WS_VSCROLL |
                                     WS_TABSTOP,
                                     0, 0, 0, 0, hwnd, NULL,
                                     ((LPCREATESTRUCT) lParam) -> hInstance,
                                     NULL) ;

            // create edit window
            hwndEdit = CreateWindow ("RICHEDIT", NULL,
                                     WS_CHILD | WS_BORDER | ES_AUTOHSCROLL,
                                     0, 0, 0, 0, hwnd, NULL,
                                     ((LPCREATESTRUCT) lParam) -> hInstance,
                                     NULL) ;

            // get subclass
            WndProcText = (WNDPROC) SetWindowLong (hwndText, GWL_WNDPROC,
                                                   (LONG) TELNET_TextSubclass) ;

            WndProcEdit = (WNDPROC) SetWindowLong (hwndEdit, GWL_WNDPROC,
                                                   (LONG) TELNET_EditSubclass) ;

            // set background color
            SendMessage (hwndText, EM_SETBKGNDCOLOR, FALSE, (LPARAM) clrBackground) ;

            SendMessage (hwndEdit, EM_SETBKGNDCOLOR, FALSE, (LPARAM) clrBackground) ;

            // colorize
            TELNET_Colorize () ;

            SendMessage (hwndText, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cfText) ;

            // set font
            TELNET_SetFont () ;

            // create timer
            nTimerCount = 0 ;
            nTimer      = SetTimer (hwnd, TIMER_COMMAND_ID, 60 * 1000, NULL) ;

            // clear both window
            SetWindowText (hwndText, "") ;
            SetWindowText (hwndEdit, "") ;

            // add first line to get rid of initial flashing
            TELNET_Write ("\n") ;

            // display both window
            ShowWindow (hwndText, SW_SHOW) ;
            ShowWindow (hwndEdit, SW_SHOW) ;
            return 0 ;

        case WM_SIZE :
            SendMessage (hwndText, EM_EXGETSEL, 0, (LPARAM) &TmpSel) ;

            if (IsIconic (hwnd))
                {
                }
            else
                {
                hdc = GetDC (hwndEdit) ;

                hfOld = (HFONT) SelectObject (hdc, hfFont.hfFont) ;

                GetTextExtentPoint32 (hdc, "W", 1, &szLine) ;

                SelectObject (hdc, hfOld) ;

                ReleaseDC (hwndEdit, hdc) ;

                nH = (szLine.cy * 7) >> 2 ;

                MoveWindow (hwndText, 0, 0, LOWORD (lParam), HIWORD (lParam) - nH, TRUE) ;

                MoveWindow (hwndEdit, 0, HIWORD (lParam) - nH,
                            LOWORD (lParam), nH, TRUE) ;

                TELNET_GoBottom () ;
                }

            SendMessage (hwndText, EM_EXSETSEL, 0, (LPARAM) &TmpSel) ;
            PostMessage (hwndText, EM_EXGETSEL, 0, (LPARAM) &TmpSel) ;
            PostMessage (hwndText, EM_HIDESELECTION, FALSE, FALSE) ;

            SetFocus (hwndEdit) ;
            break ;

        case WM_PAINT :
            hdc = BeginPaint (hwnd, &ps) ;

            GetClientRect (hwnd, &rc) ;

            EndPaint (hwnd, &ps) ;
            return 0 ;

        case WSA_READ :
            if (TSInput.count == 0)
                {
                TOOLBOX_CloseSocket () ;
                TELNET_Write (" || Program -> Connection closed by ics.\n") ;
                return 0 ;
                }
			
            strcpy (SocketBuffer, TSInput.buf) ;

            cStart = SocketBuffer ;
            cEnd   = SocketBuffer ;

            if (bBeforeLogin)
                {
                while (bSocketIsOpen)
                    {
                    while (*cEnd != 1  &&
                           *cEnd != 13 &&
                           *cEnd != NULL_CHAR)
                        {
                        PARSE_CheckPressReturn (cEnd) ;
                        cEnd++ ;
                        }

                    if (*cEnd == NULL_CHAR)
                        {
                        if (bBeforeLogin)
                            {
                            PARSE_BeforeLoginLine (cStart) ;
                            }
                        else
                            {
                            PARSE_Line (cStart) ;
                            }
                        break ;
                        }

                    if (cEnd != cStart)
                        {
                        *cEnd = NULL_CHAR ;

                        if (bBeforeLogin)
                            {
                            PARSE_BeforeLoginLine (cStart) ;
                            }
                        else
                            {
                            PARSE_Line (cStart) ;
                            }
                        }

                    cStart = cEnd + 1 ;
                    cEnd   = cStart ;
                    }

                if (! bBeforeLogin)
                    {
                    strcpy (SocketLine, "") ;

                    bSocketLine = 0 ;

                    TOOLBOX_SetupWinTitle () ;

                    SCRIPT_Read () ;

                    TOOLBOX_IssueFingerNote () ;

                    TOOLBOX_IssueIAmOn () ;
                    }
                }
            else
                {
                while (bSocketIsOpen)
                    {
                    while (*cEnd != 13 && *cEnd != NULL_CHAR)
                        {
                        cEnd++ ;
                        }

                   if (*cEnd == NULL_CHAR)
                        {
                        if (bSocketLine)
                            {
                            strcat (SocketLine, cStart) ;
                            }
                        else
                            {
                            strcpy (SocketLine, cStart) ;
                            bSocketLine = 1 ;
                            }
                        break ;
                        }

                    if (bSocketLine)
                        {
                        *cEnd = NULL_CHAR ;

                        strcat (SocketLine, cStart) ;
                        bSocketLine = 0 ;

                        PARSE_Line (SocketLine) ;
                        }
                    else
                        {
                        if (cEnd != cStart)
                            {
                            *cEnd = NULL_CHAR ;

                            PARSE_Line (cStart) ;
                            }
                        }

                    cStart = cEnd + 1 ;
                    cEnd   = cStart ;
                    }
                }
		
            TSInput.next = TSInput.buf ;
            break ;

        case WM_TIMER :
            if (++nTimerCount >= nTimerMinute)
                {
                if (bSocketIsOpen)
                    {
                    strcpy (Tmp, TimerCommand) ;
                    strcat (Tmp, "\n") ;

                    TIMESEAL_Write (Tmp) ;
                    TELNET_Write   (Tmp) ;

                    SetFocus (hwndEdit) ;

                    nTimerCount = 0 ;
                    }
                else
                    {
                    TOOLBOX_CloseSocket () ;

                    SetWindowText (hwndText, "") ;
                    SetWindowText (hwndEdit, "") ;

                    TIMESEAL_Load () ;
                    }
                }
        break ;

        case WM_CLOSE :
            TOOLBOX_SaveWindowCoord () ;

            TIMESEAL_Write (ICS_QUIT_COMMAND) ;

            TOOLBOX_CloseSocket () ;
            break ;

        case WM_DESTROY :
            if (nTimer != -1)
                {
                KillTimer (hwnd, TIMER_COMMAND_ID) ;
                nTimer = -1 ;
                }

            WSACleanup() ;
            PostQuitMessage (0) ;
            return 0 ;
        }

    return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
    }
Example #8
0
void INI_WriteSys (void)
    {
    FILE *Fv ;

    char Drive [_MAX_DRIVE] ;
    char Dir   [_MAX_DIR] ;
    char File  [_MAX_FNAME] ;
    char Ext   [_MAX_EXT] ;
    char Ini   [_MAX_PATH] ;

    char Tmp   [1024] ;

    int  nI ;

    // generate a full path SETUP.TXT

    _splitpath (InstallDir, Drive, Dir, File, Ext) ;

    strcpy (File, INI_NAME) ;
    strcpy (Ext,  INI_EXT) ;

    _makepath (Ini, Drive, Dir, File, Ext) ;

    // open
    Fv = fopen (Ini, "w") ;
    if (Fv == NULL)
        {
        sprintf (Tmp, "\n || Writing %s failed\n\n", Ini) ;
        TELNET_Write (Tmp) ;
        return ;
        }

    // write comments

    fprintf (Fv, ";\n") ;
    fprintf (Fv, "; TBOT settings file\n") ;
    fprintf (Fv, ";\n") ;
    fprintf (Fv, "; Server=0 --> USCL 5000 (valid guest channels: 1, 2, 24, 50)\n") ;
    fprintf (Fv, "; Server=1 --> FICS 5000 (valid guest channels: 1 to 255)\n") ;
    fprintf (Fv, "; Server=2 --> FICS 23   (valid guest channels: 1 to 255)\n") ;
    fprintf (Fv, ";\n") ;

    // [Main]
    fprintf (Fv, "[Main]\n") ;

    // server
    fprintf (Fv, "Server=%d\n", nFICS) ;

    // state
    fprintf (Fv, "State=%d\n", nState) ;

    // handle
    fprintf (Fv, "Handle=%s\n", Handle) ;

    // password
    fprintf (Fv, "Password=%s\n", Password) ;

    // coordinate
    sprintf (Tmp, "%d %d %d %d %d", wCoord.x, wCoord.y, wCoord.w, wCoord.h, bMaximizeMain) ;
    fprintf (Fv, "Coordinate=%s\n", Tmp) ;
    
    // font
    sprintf (Tmp, "%s,%d,%d,%d,%d,%d",
                  hfFont.Name,
                  hfFont.nPointSize,
                  hfFont.bBold      ? 1 : 0,
                  hfFont.bItalic    ? 1 : 0,
                  hfFont.bUnderLine ? 1 : 0,
                  hfFont.bStrikeOut ? 1 : 0) ;

    fprintf (Fv, "Font=%s\n", Tmp) ;
    
    // foreground color
    fprintf (Fv, "Foreground=%06lx\n", clrForeground) ;

    // background color
    fprintf (Fv, "Background=%06lx\n", clrBackground) ;

    // channel
    fprintf (Fv, "Channel=%d\n", nChannel) ;

    // arbiter
    fprintf (Fv, "Arbiter=%s\n", cArbiter) ;

    // arb
    for (nI = 0 ; nI < MAX_ARB ; nI++)
        {
        fprintf (Fv, "Arb #%d=%s\n", nI + 1, Arb [nI].cHandle) ;
        }

    // eligible
    fprintf (Fv, "Eligible game=%d\n",      nEligibleGame) ;
    fprintf (Fv, "Eligible best 1=%d\n",    nEligibleBest1) ;
    fprintf (Fv, "Eligible current 1=%d\n", nEligibleCurrent1) ;
    fprintf (Fv, "Eligible best 2=%d\n",    nEligibleBest2) ;
    fprintf (Fv, "Eligible current 2=%d\n", nEligibleCurrent2) ;

    // semi-eligible
    fprintf (Fv, "Semi-eligible game=%d\n",      nSemiEligibleGame) ;
    fprintf (Fv, "Semi-eligible best 1=%d\n",    nSemiEligibleBest1) ;
    fprintf (Fv, "Semi-eligible current 1=%d\n", nSemiEligibleCurrent1) ;
    fprintf (Fv, "Semi-eligible best 2=%d\n",    nSemiEligibleBest2) ;
    fprintf (Fv, "Semi-eligible current 2=%d\n", nSemiEligibleCurrent2) ;

    // close
    fclose (Fv) ;
    }