Приветствую всех! Нуждаюсь в вашей помощи господа.
Есть файл, в него записывается данные (текст) через какойто промежуток времени.
Вот пример из файла:
Цитата |
L 12/04/2011 - 16:17:38: "[komanda1]Maxim<616><STEAM_0:0:654865451><616>" killed "Sanyok<621><STEAM_ID_LAN><621>" with "crossbow" (attacker_position "-225 -825 740") (victim_position "192 -817 740") L 12/04/2011 - 16:17:40: "pitbull<600><STEAM_ID_LAN><600>" committed suicide with "rpg_rocket" (attacker_position "-497 -822 740") L 12/04/2011 - 16:17:40: "pitbull<600><STEAM_ID_LAN><600>" killed "[komanda1]Maxim<616><STEAM_0:0:654865451><616>" with "rpg_rocket" (attacker_position "-497 -822 740") (victim_position "-465 -822 740") L 12/04/2011 - 16:17:44: "Player<620><STEAM_ID_LAN><620>" committed suicide with "rpg_rocket" (attacker_position "815 -812 740") L 12/04/2011 - 16:17:54: "[komanda2]Mapk<625><STEAM_0:0:695887895><625>" say "Здорова Максим =))" L 12/04/2011 - 16:17:55: "Player<620><STEAM_ID_LAN><620>" killed "Sanyok<621><STEAM_ID_LAN><621>" with "shotgun" (attacker_position "232 12 48") (victim_position "12 -22 48") L 12/04/2011 - 16:17:56: "Den<622><STEAM_0:0:837209638><622>" committed suicide with "rpg_rocket" (attacker_position "721 995 48") L 12/04/2011 - 16:17:56: "[komanda1]Maxim<616><STEAM_0:0:654865451><616>" killed "S.T.A.L.K.E.R.<611><STEAM_ID_LAN><611>" with "tripmine" (attacker_position "541 -898 48") (victim_position "2 -484 164") L 12/04/2011 - 16:18:01: "[komanda1]Maxim<616><STEAM_0:0:654865451><616>" say "привет." |
Цитата |
12/04/2011 - 16:17:54 Ник_игрока: Сообщение_игрока |
Цитата (Winston @ 4.12.2011 - 23:24) |
Может я плохо в этом понимаю, но покажи мне где здесь имя игроков и сообщения ? |
Цитата |
L 12/04/2011 - 16:18:01: "[komanda1]Maxim<616><STEAM_0:0:654865451><616>" say "привет." |
preg_match_all('#([ \d:/-]{24}).*](.*)<\d+>.*say "(.*)"#isuU', $str, $match);
echo '<pre>'.htmlspecialchars(print_r($match, 1)).'</pre>';
<?php
$str = file_get_contents('mylog.log');
preg_match_all('#([ \d:/-]{24}).*](.*)<\d+>.*say "(.*)"#isuU', $str, $match);
echo '<pre>'.htmlspecialchars(print_r($match, 1)).'</pre>';
?>
Array
(
[0] => Array
(
)
[1] => Array
(
)
[2] => Array
(
)
[3] => Array
(
)
)
#include <amxmodx>
#include <cstrike>
public plugin_init()
{
// Register the plugin
register_plugin("[AMX] Chat Logger", "0.0.1", "NullWarez")
// Client say commands
register_clcmd("say", "hook_say")
register_clcmd("say_team", "hook_say")
}
public hook_say(id)
{
if(!is_user_connected(id))
return PLUGIN_HANDLED
static chat[192], name[32], logdata[223]
// Process what he is speaking
read_args(chat, 191)
remove_quotes(chat)
if(equal(chat, ""))
return PLUGIN_CONTINUE
// Get his name
get_user_name(id, name, 31)
// 12/04/2011 - 16:17:54 Ник_игрока: Сообщение_игрока
formatex(logdata, charsmax(logdata), "%s: %s", name, chat)
log_to_file("user_chat.log", logdata)
return PLUGIN_CONTINUE
}
#include <amxmodx>
#include <cstrike>
#include <sqlx>
#define DB_RECCONECT_TIME 5.0 // Time to reconnect db if fail
#define DB_TABLE_NAME "chat_logger"
// ERROR VAR
new g_ErrorCode, g_ErrorMsg[256]
// SQL VAR
new Handle:g_hSQLTuple, Handle:g_hSQLConnection, g_szQuery[256]
/*================================================================================
[INIT]
=================================================================================*/
public plugin_init()
{
// Register the plugin
register_plugin("[AMX] Chat Logger", "0.1.0", "NullWarez")
// Client say commands
register_clcmd("say", "hook_say")
register_clcmd("say_team", "hook_say")
// Connect to MySQL
ConnectDataBase();
}
/*================================================================================
[FUNCTIONS]
=================================================================================*/
public ConnectDataBase()
{
g_hSQLTuple = SQL_MakeStdTuple()
g_hSQLConnection = SQL_Connect(g_hSQLTuple, g_ErrorCode, g_ErrorMsg, 256)
if(g_hSQLConnection == Empty_Handle)
{
set_task(DB_RECCONECT_TIME, "ConnectDataBase")
log_amx("ConnectDataBase(): SQL Error #%d - %s", g_ErrorCode, g_ErrorMsg)
}
return PLUGIN_CONTINUE;
}
public hook_say(id)
{
if(g_hSQLConnection == Empty_Handle)
return PLUGIN_CONTINUE
if(!is_user_connected(id))
return PLUGIN_HANDLED
static chat[192], name[32]
// Process what he is speaking
read_args(chat, 191)
remove_quotes(chat)
if(equal(chat, ""))
return PLUGIN_CONTINUE
// Get his name
get_user_name(id, name, 31)
// Escape screening
replace_all(name, 31, "'", "\'")
replace_all(chat, 191, "'", "\'")
// Sql request
formatex(g_szQuery, charsmax(g_szQuery),"INSERT INTO `%s`.`chat` (`id` ,`nick` ,`text`) VALUES (NULL, '%s', '%s');", DB_TABLE_NAME, name, chat);
SQL_SimpleQuery(g_hSQLConnection, g_szQuery)
return PLUGIN_CONTINUE
}
CREATE TABLE IF NOT EXISTS `chat` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nick` varchar(31) NOT NULL,
`text` varchar(191) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=1 ;
Цитата (RCuPeR @ 5.12.2011 - 02:11) |
Свернутый текст А на каком языке это вообще написано ? |
Цитата |
Попробуй убрать модификатор u, если у тебя кодировка windows-1251. А скорее так и есть, если txt-файл. |
<?php
$str = file_get_contents('mylog_2.log');
preg_match_all('#([ \d:/-]{24}).*](.*)<\d+>.*say "(.*)"#isU', $str, $match);
echo '<pre>'.htmlspecialchars(print_r($match, 1)).'</pre>';
?>
Цитата |
Array ( [0] => Array ( [0] => 12/04/2011 - 16:17:38: "[komanda1]Maxim<616><STEAM_0:0:654865451><616>" killed "Sanyok<621><STEAM_ID_LAN><621>" with "crossbow" (attacker_position "-225 -825 740") (victim_position "192 -817 740") L 12/04/2011 - 16:17:40: "pitbull<600><STEAM_ID_LAN><600>" committed suicide with "rpg_rocket" (attacker_position "-497 -822 740") L 12/04/2011 - 16:17:40: "pitbull<600><STEAM_ID_LAN><600>" killed "[komanda1]Maxim<616><STEAM_0:0:654865451><616>" with "rpg_rocket" (attacker_position "-497 -822 740") (victim_position "-465 -822 740") L 12/04/2011 - 16:17:44: "Player<620><STEAM_ID_LAN><620>" committed suicide with "rpg_rocket" (attacker_position "815 -812 740") L 12/04/2011 - 16:17:54: "[komanda2]Mapk<625><STEAM_0:0:695887895><625>" say "Здорова Максим =))" [1] => 12/04/2011 - 16:17:55: "Player<620><STEAM_ID_LAN><620>" killed "Sanyok<621><STEAM_ID_LAN><621>" with "shotgun" (attacker_position "232 12 48") (victim_position "12 -22 48") L 12/04/2011 - 16:17:56: "Den<622><STEAM_0:0:837209638><622>" committed suicide with "rpg_rocket" (attacker_position "721 995 48") L 12/04/2011 - 16:17:56: "[komanda1]Maxim<616><STEAM_0:0:654865451><616>" killed "S.T.A.L.K.E.R.<611><STEAM_ID_LAN><611>" with "tripmine" (attacker_position "541 -898 48") (victim_position "2 -484 164") L 12/04/2011 - 16:18:01: "[komanda1]Maxim<616><STEAM_0:0:654865451><616>" say "привет." ) [1] => Array ( [0] => 12/04/2011 - 16:17:38: [1] => 12/04/2011 - 16:17:55: ) [2] => Array ( [0] => Maxim [1] => Maxim ) [3] => Array ( [0] => Здорова Максим =)) [1] => привет. ) ) |
Цитата (lua @ 5.12.2011 - 09:18) |
ВЫВОД |
Цитата |
Уважаемый I++ самый прикол в том, что сервер не у меня стоит. Мне доступен только файл лога этого сервера, которы лежит на фтп и обновляется за какоето промежуточное время. ftp:/lalala/mylog.log |