Commit ac5f916d authored by Nemo Ma's avatar Nemo Ma Committed by GitHub

Merge pull request #173 from clean-master/feature/server-record

增加录像上传的功能
parents 8655d428 b0e30300
...@@ -80,3 +80,6 @@ vendor ...@@ -80,3 +80,6 @@ vendor
# env file # env file
.env .env
# 录像文件
records
...@@ -573,7 +573,7 @@ function skill_unacquired_mouseout(e) ...@@ -573,7 +573,7 @@ function skill_unacquired_mouseout(e)
//录制处理 //录制处理
var recordedData = []; var recordedData = [];
var isRecording = false; var isRecording = true;
function startRecording() { function startRecording() {
isRecording = true; isRecording = true;
console.log('startRecording'); console.log('startRecording');
...@@ -587,7 +587,9 @@ function startRecording() { ...@@ -587,7 +587,9 @@ function startRecording() {
linkElement.setAttribute('onclick', 'stopRecording()'); linkElement.setAttribute('onclick', 'stopRecording()');
} }
} }
document.addEventListener('click', recordButtonClick);
function stopRecording() { function stopRecording() {
isRecording = false; isRecording = false;
...@@ -599,7 +601,7 @@ function stopRecording() { ...@@ -599,7 +601,7 @@ function stopRecording() {
// 停止监听 // 停止监听
document.removeEventListener('click', recordButtonClick); document.removeEventListener('click', recordButtonClick);
downloadRecordedData(); //downloadRecordedData();
} }
function downloadRecordedData() { function downloadRecordedData() {
...@@ -620,6 +622,7 @@ function recordButtonClick(event) { ...@@ -620,6 +622,7 @@ function recordButtonClick(event) {
// 如果录制状态为 true,则将当前前端的全部静态网页数据保存到数组中 // 如果录制状态为 true,则将当前前端的全部静态网页数据保存到数组中
if (isRecording) { if (isRecording) {
recordedData.push(document.documentElement.outerHTML.concat("\n")); recordedData.push(document.documentElement.outerHTML.concat("\n"));
sendLastRecordedData(recordedData);
} }
} }
...@@ -664,6 +667,20 @@ function showPage(pageContent, currentPageIndex) { ...@@ -664,6 +667,20 @@ function showPage(pageContent, currentPageIndex) {
recordedDataDiv.innerHTML = '已经到达最后一页'; recordedDataDiv.innerHTML = '已经到达最后一页';
} }
}; };
// 阻止链接跳转
var links = recordedDataDiv.getElementsByTagName('a');
for (var i = 0; i < links.length; i++) {
links[i].addEventListener('click', function (event) {
event.preventDefault();
});
}
// 删除具有 id="hidden-model" 的元素
var hiddenModelElement = document.getElementById('hidden-model');
if (hiddenModelElement) {
hiddenModelElement.remove();
}
recordedDataDiv.insertBefore(nextPageButton, recordedDataDiv.firstChild); recordedDataDiv.insertBefore(nextPageButton, recordedDataDiv.firstChild);
...@@ -706,12 +723,41 @@ function displayRecordedData(file) { ...@@ -706,12 +723,41 @@ function displayRecordedData(file) {
} }
} }
window.onbeforeunload = function () { /*window.onbeforeunload = function () {
if (isRecording) { if (isRecording) {
window.alert('你正在录制游戏,之后将会自动下载录制数据。'); window.alert('你正在录制游戏,之后将会自动下载录制数据。');
downloadRecordedData(); downloadRecordedData();
} }
}; };*/
function sendLastRecordedData(recordedData) {
const nickinfoElement = document.getElementById('nickinfo');
if (!nickinfoElement) {
return;
}
const nickinfo = nickinfoElement.innerText;
const lastRecord = recordedData[recordedData.length - 1];
fetch('record_backend.php', {
method: 'POST',
body: JSON.stringify({ lastRecord, nickinfo }),
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
// 处理从后端返回的响应
//console.log(data);
})
.catch(error => {
// 处理错误
console.error(error);
});
}
...@@ -440,6 +440,19 @@ function duel($time = 0,$keyitm = ''){ ...@@ -440,6 +440,19 @@ function duel($time = 0,$keyitm = ''){
function gameover($time = 0, $mode = '', $winname = '') { function gameover($time = 0, $mode = '', $winname = '') {
global $gamestate,$winmode,$alivenum,$winner,$now,$gamenum,$db,$gtablepre,$tablepre,$gamenum,$starttime,$validnum,$hdamage,$hplayer; global $gamestate,$winmode,$alivenum,$winner,$now,$gamenum,$db,$gtablepre,$tablepre,$gamenum,$starttime,$validnum,$hdamage,$hplayer;
global $groomid; global $groomid;
//遍历./records/$gamenum/下的所有txt文件
$filelist = glob("./records/$gamenum/**/*.txt");
//然后gzip压缩
foreach($filelist as $file){
$input = fopen($file, 'rb');
$output = gzopen($file . '.gz', 'wb');
while (!feof($input)) {
gzwrite($output, fread($input, 1024));
}
fclose($input);
//删除原文件
unlink($file);
}
if($gamestate < 10){return;} if($gamestate < 10){return;}
if((!$mode)||(($mode==2)&&(!$winname))) {//在没提供游戏结束模式的情况下,自行判断模式 if((!$mode)||(($mode==2)&&(!$winname))) {//在没提供游戏结束模式的情况下,自行判断模式
if($validnum <= 0) {//无激活者情况下,全部死亡 if($validnum <= 0) {//无激活者情况下,全部死亡
......
<?php
define('CURSCRIPT', 'record_backend');
require './include/common.inc.php';
try {
$jsonData = file_get_contents('php://input');
$requestData = json_decode($jsonData, true);
if ($requestData === null) {
http_response_code(400);
$response = ["message" => "Invalid JSON data"];
echo json_encode($response);
return;
}
global $gamenum;
$lastRecord = $requestData['lastRecord'];
$nickinfo = $requestData['nickinfo'];
$directoryPath = "./records/$gamenum/$nickinfo";
$filePath = "$directoryPath/record.txt";
// 创建目录
if (!is_dir($directoryPath) && !mkdir($directoryPath, 0777, true)) {
throw new Exception('Failed to create directory');
}
// 写入数据到文件
if (!file_put_contents($filePath, $lastRecord . "\n", FILE_APPEND)) {
throw new Exception('Failed to write data to file');
}
// 返回信息
echo json_encode([
"message" => "Success",
]);
} catch (Exception $e) {
http_response_code(500);
$response = ["message" => $e->getMessage()];
echo json_encode($response);
}
...@@ -206,7 +206,7 @@ ...@@ -206,7 +206,7 @@
</div> </div>
</a> </a>
</span> </span>
<a href="javascript:void(0)" onclick="startRecording()">>>开始录像</a> <a href="javascript:void(0)" onclick="stopRecording()">>>停止录像</a>
<a href="record.php">>>回放录像</a> <a href="record.php">>>回放录像</a>
<a href="admin.php">>>{lang admin}</a> <a href="admin.php">>>{lang admin}</a>
<a href="https://bbs.brdts.online/" target="_blank">>>{lang report}</a> <a href="https://bbs.brdts.online/" target="_blank">>>{lang report}</a>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<table border="0" width="720" cellspacing="0" cellpadding="0" valign="middle"> <table border="0" width="720" cellspacing="0" cellpadding="0" valign="middle">
<tr> <tr>
<!--{eval $nickinfo = titles_get_desc($nick,1);}--> <!--{eval $nickinfo = titles_get_desc($nick,1);}-->
<td width="210" colspan="3" class="b1"><span>{$nickinfo} {$name}</span></td> <td width="210" colspan="3" class="b1" id="nickinfo"><span>{$nickinfo} {$name}</span></td>
<td width="100" colspan="1" class="b1"><span>{$sexinfo[$gd]}{$sNo}号</span></td> <td width="100" colspan="1" class="b1"><span>{$sexinfo[$gd]}{$sNo}号</span></td>
<td width="95" colspan="2" class="b1"><span>{lang weather}:$wthinfo[$weather]</span></td> <td width="95" colspan="2" class="b1"><span>{lang weather}:$wthinfo[$weather]</span></td>
<td width="215" colspan="1" class="b1"><span>{lang gamedate}<!--{if $gamestate == 40 }--><span class="yellow">{lang combo}</span><!--{/if}--><!--{if $gamestate == 50 }--><span class="red">{lang duel}</span><!--{/if}--></span></td> <td width="215" colspan="1" class="b1"><span>{lang gamedate}<!--{if $gamestate == 40 }--><span class="yellow">{lang combo}</span><!--{/if}--><!--{if $gamestate == 50 }--><span class="red">{lang duel}</span><!--{/if}--></span></td>
......
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
<input type="button" value="角色信息" <!--{if $info['wmode'] && $info['wmode'] != 1 && $info['wmode'] !=4 && $info['wmode'] != 6}-->onclick="$('command').value='info';$('gnum').value='$gid';document.info.submit();"<!--{else}-->disabled<!--{/if}-->> <input type="button" value="角色信息" <!--{if $info['wmode'] && $info['wmode'] != 1 && $info['wmode'] !=4 && $info['wmode'] != 6}-->onclick="$('command').value='info';$('gnum').value='$gid';document.info.submit();"<!--{else}-->disabled<!--{/if}-->>
<!--{if $info['wmode'] && $info['wmode'] !=4}--><span class="white"><a href="winner.php?command=news&gnum=$info[gid]">📼</a></span><!--{else}--> <!--{/if}--> <!--{if $info['wmode'] && $info['wmode'] !=4}--><span class="white"><a href="winner.php?command=news&gnum=$info[gid]">📼</a></span><!--{else}--> <!--{/if}-->
<input type="button" value="该局状况" <!--{if $info['wmode'] && $info['wmode'] !=4}-->onclick="$('command').value='news';$('gnum').value='$gid';document.info.submit();"<!--{else}-->disabled<!--{/if}-->> <input type="button" value="该局状况" <!--{if $info['wmode'] && $info['wmode'] !=4}-->onclick="$('command').value='news';$('gnum').value='$gid';document.info.submit();"<!--{else}-->disabled<!--{/if}-->>
$download_buttons[$gid]
</span> </span>
</TD> </TD>
</TR> </TR>
......
...@@ -23,6 +23,7 @@ if($command == 'info') { ...@@ -23,6 +23,7 @@ if($command == 'info') {
$hnewsinfo = readover($hnewsfile); $hnewsinfo = readover($hnewsfile);
} }
} else { } else {
$download_button = [];
if(!isset($start) || !$start){ if(!isset($start) || !$start){
$result = $db->query("SELECT gid,name,nick,icon,gd,wep,wmode,teamID,teamMate,teamIcon,getime,motto,hdp,hdmg,hkp,hkill FROM {$gtablepre}winners ORDER BY gid desc LIMIT $winlimit"); $result = $db->query("SELECT gid,name,nick,icon,gd,wep,wmode,teamID,teamMate,teamIcon,getime,motto,hdp,hdmg,hkp,hkill FROM {$gtablepre}winners ORDER BY gid desc LIMIT $winlimit");
} else { } else {
...@@ -50,7 +51,14 @@ if($command == 'info') { ...@@ -50,7 +51,14 @@ if($command == 'info') {
$wdata['nickinfo'] = (!empty($wdata['nick']) || $wdata['nick'] === '0') ? titles_get_desc($wdata['nick']) : ''; $wdata['nickinfo'] = (!empty($wdata['nick']) || $wdata['nick'] === '0') ? titles_get_desc($wdata['nick']) : '';
} }
} }
$winfo[$wdata['gid']] = $wdata; $winfo[$wdata['gid']] = $wdata;
//遍历./records/$wdata['gid']/下的所有gz文件
$filelist = glob("./records/{$wdata['gid']}/**/*.gz");
foreach ($filelist as $file) {
//下载按钮,html
$dirname = basename(dirname($file));
$download_buttons[$wdata['gid']] .= "<br><a href=\"$file\" download=\"$dirname\">下载 $dirname</a>";
}
} }
$listnum = floor($gamenum/$winlimit); $listnum = floor($gamenum/$winlimit);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment