summary refs log tree commit diff stats
path: root/plugins/mpcinfo/theme.c
blob: 000c00b19dc6c72da774cc06a7f512e3465d33bc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <time.h>

struct theme{
       int size;
       char **line;
};

static struct theme notRunTheme;
static struct theme titleTheme;
static struct theme mp3Theme;
static struct theme oggTheme;


void themeInit(){
     //if (DEBUG==1) putlog("init theme");
     /*mp3Theme.size=0;oggTheme.size=0;cueTheme.size=0;streamTheme.size=0;etcTheme.size=0;
     stopTheme.size=0;pauseTheme.size=0;*/
     
     notRunTheme.size=0;titleTheme.size=0;
     srand((unsigned int)time((time_t *)NULL));
     //if (DEBUG==1) putlog("theme init done");
}

void printTheme(struct theme data){
     int i;
     for (i=0;i<data.size;i++) xchat_printf(ph,"line[%i]=%s\n",i,data.line[i]);
}

void printThemes(){
     xchat_printf(ph,"\nNotRun-Theme:\n");printTheme(notRunTheme);
     xchat_printf(ph,"\nMP3-Theme:\n");printTheme(mp3Theme);
     xchat_printf(ph,"\nOGG-Theme:\n");printTheme(oggTheme);
     xchat_printf(ph,"\nTitle-Theme:\n");printTheme(titleTheme);
}

void cbFix(char *line){
     //if (DEBUG==1) putlog("cbfix");
     int i, j;
     for (i=0;i<strlen(line);i++){
         if (line[i]=='%'){
            if ((line[i+1]=='C')||(line[i+1]=='B')||(line[i+1]=='U')||(line[i+1]=='O')||(line[i+1]=='R')){
               if(line[i+1]=='C') line[i]=3;
               if(line[i+1]=='B') line[i]=2;
               if(line[i+1]=='U') line[i]=37;
               if(line[i+1]=='O') line[i]=17;
               if(line[i+1]=='R') line[i]=26;

               for (j=i+1;j<strlen(line)-1;j++) line[j]=line[j+1];
               line[strlen(line)-1]=0;
            }
         }
     }
     //if (DEBUG==1) putlog("cbfix done");
}

struct theme themeAdd(struct theme data, char *info){
       //if (DEBUG==1) putlog("adding theme");
       struct theme ret;
       char **newLine=(char **)calloc(data.size+1,sizeof(char*));
       int i;
       for (i=0;i<data.size;i++) newLine[i]=data.line[i];
       cbFix(info);
       newLine[data.size]=info;
       ret.line=newLine;ret.size=data.size+1;
       //if (DEBUG==1) putlog("theme added");
       return ret;
}

void loadThemes(){
    char *hDir, *hFile, *line, *val;
	FILE *f;
	xchat_print(ph,"loading themes\n");
    hDir=(char*)calloc(1024,sizeof(char));
    strcpy(hDir,xchat_get_info(ph,"xchatdirfs"));
    hFile=str3cat(hDir,"\\","mpcInfo.theme.txt");
    f = fopen(hFile,"r");
    if(f==NULL)
	{
		xchat_print(ph,"no theme in homedir, checking global theme");
		f=fopen("mpcInfo.theme.txt","r");
    }
	//xchat_printf(ph,"file_desc: %p\n",f);
	if (f==NULL) xchat_print(ph, "no theme found, using hardcoded\n");
	else {
		if (f > 0)
		{
			line=" ";
		} else
		{
			line="\0";
		}

		while (line[0]!=0)
		{
			line=readLine(f);
			val=split(line,'=');
			printf("line: %s\n",line);
			printf("val: %s\n",val);
			if (strcmp(toUpper(line),"OFF_LINE")==0) notRunTheme=themeAdd(notRunTheme,val);
			if (strcmp(toUpper(line),"TITLE_LINE")==0) titleTheme=themeAdd(titleTheme,val);
			if (strcmp(toUpper(line),"MP3_LINE")==0) mp3Theme=themeAdd(mp3Theme,val);
			if (strcmp(toUpper(line),"OGG_LINE")==0) mp3Theme=themeAdd(oggTheme,val);
		}
		fclose(f);
		xchat_print(ph, "theme loaded successfull\n");
	}
	if (notRunTheme.size==0) notRunTheme=themeAdd(notRunTheme,"say Media Player Classic not running");
	if (titleTheme.size==0) titleTheme=themeAdd(titleTheme,"say Playing %title in Media Player Classic");
	if (mp3Theme.size==0) mp3Theme=themeAdd(mp3Theme,"me listens to %art with %tit from %alb [%gen|%br kbps|%frq kHz|%mode] in Media Player Classic ");
	if (oggTheme.size==0) oggTheme=themeAdd(oggTheme,"me listens to %art with %tit from %alb [%gen|%br kbps|%frq kHz|%chan channels] in Media Player Classic ");
	//mp3Theme=themeAdd(mp3Theme,"me listens to %art with %tit from %alb [%time|%length|%perc%|%br kbps|%frq kHz|%mode] in Media Player Classic ");
}

int rnd(int max){
    return rand()%max;
}

char *randomLine(struct theme data){
     return data.line[rnd(data.size)];
}
ss="o">= 1; uw < XCHAT_MAX_WORDS; uw++) { if (word[uw][0] != '\0' && !append(&message, &length, " ")) goto decrypt_error; if (uw == ew) { // Add the encrypted data peice = decrypted; uw++; // Skip "OK+" if (ew == w+1) { // Prefix with colon, which gets stripped out otherwise if (!append(&message, &length, ":")) goto decrypt_error; } } else { // Add unencrypted data (for example, a prefix from a bouncer or bot) peice = word[uw]; } if (!append(&message, &length, peice)) goto decrypt_error; } free(decrypted); // Simulate unencrypted message //xchat_printf(ph, "simulating: %s\n", message); xchat_command(ph, message); free(message); free(sender_nick); return XCHAT_EAT_XCHAT; decrypt_error: free(decrypted); free(sender_nick); return XCHAT_EAT_NONE; } /** * Command handler for /setkey */ static int handle_setkey(char *word[], char *word_eol[], void *userdata) { const char *nick; const char *key; // Check syntax if (*word[2] == '\0') { xchat_printf(ph, "%s\n", usage_setkey); return XCHAT_EAT_XCHAT; } if (*word[3] == '\0') { // /setkey password nick = xchat_get_info(ph, "channel"); key = word_eol[2]; } else { // /setkey #channel password nick = word[2]; key = word_eol[3]; } // Set password if (keystore_store_key(nick, key)) { xchat_printf(ph, "Stored key for %s\n", nick); } else { xchat_printf(ph, "\00305Failed to store key in blow.ini\n", nick, key); } return XCHAT_EAT_XCHAT; } /** * Command handler for /delkey */ static int handle_delkey(char *word[], char *word_eol[], void *userdata) { const char *nick; // Check syntax if (*word[2] == '\0' || *word[3] != '\0') { xchat_printf(ph, "%s\n", usage_delkey); return XCHAT_EAT_XCHAT; } nick = word_eol[2]; // Delete the given nick from the key store if (keystore_delete_nick(nick)) { xchat_printf(ph, "Deleted key for %s\n", nick); } else { xchat_printf(ph, "\00305Failed to delete key in blow.ini!\n", nick); } return XCHAT_EAT_XCHAT; } /** * Returns the plugin name version information. */ void xchat_plugin_get_info(const char **name, const char **desc, const char **version, void **reserved) { *name = plugin_name; *desc = plugin_desc; *version = plugin_version; } /** * Plugin entry point. */ int xchat_plugin_init(xchat_plugin *plugin_handle, const char **name, const char **desc, const char **version, char *arg) { ph = plugin_handle; /* Send our info to XChat */ *name = plugin_name; *desc = plugin_desc; *version = plugin_version; /* Register commands */ xchat_hook_command(ph, "SETKEY", XCHAT_PRI_NORM, handle_setkey, usage_setkey, NULL); xchat_hook_command(ph, "DELKEY", XCHAT_PRI_NORM, handle_delkey, usage_delkey, NULL); /* Add handlers */ xchat_hook_command(ph, "", XCHAT_PRI_NORM, handle_outgoing, NULL, NULL); xchat_hook_server(ph, "NOTICE", XCHAT_PRI_NORM, handle_incoming, NULL); xchat_hook_server(ph, "PRIVMSG", XCHAT_PRI_NORM, handle_incoming, NULL); //xchat_hook_server(ph, "RAW LINE", XCHAT_PRI_NORM, handle_debug, NULL); xchat_hook_server(ph, "TOPIC", XCHAT_PRI_NORM, handle_incoming, NULL); xchat_hook_server(ph, "332", XCHAT_PRI_NORM, handle_incoming, NULL); xchat_printf(ph, "%s plugin loaded\n", plugin_name); /* Return success */ return 1; } int xchat_plugin_deinit(void) { xchat_printf(ph, "%s plugin unloaded\n", plugin_name); return 1; }