Исправление багов с бд
This commit is contained in:
21
server.js
21
server.js
@@ -353,7 +353,7 @@ app.post('/api/messages/send', authenticate, async (req, res) => {
|
|||||||
const senderId = req.user.id;
|
const senderId = req.user.id;
|
||||||
const { receiverId, message } = req.body;
|
const { receiverId, message } = req.body;
|
||||||
const recvId = parseInt(receiverId, 10);
|
const recvId = parseInt(receiverId, 10);
|
||||||
|
console.log("Запрос пошел");
|
||||||
try {
|
try {
|
||||||
// Проверка существования получателя в основной БД
|
// Проверка существования получателя в основной БД
|
||||||
const receiverCheck = await db.query('SELECT id FROM users WHERE id = $1', [recvId]);
|
const receiverCheck = await db.query('SELECT id FROM users WHERE id = $1', [recvId]);
|
||||||
@@ -363,8 +363,8 @@ app.post('/api/messages/send', authenticate, async (req, res) => {
|
|||||||
|
|
||||||
// Сохранение сообщения в virtual_world
|
// Сохранение сообщения в virtual_world
|
||||||
const result = await virtualWorldPool.query(
|
const result = await virtualWorldPool.query(
|
||||||
`INSERT INTO messages (sender_id, receiver_id, message)
|
`INSERT INTO messages (sender_id, receiver_id, message, created_at)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3, NOW())
|
||||||
RETURNING id, created_at, is_read`,
|
RETURNING id, created_at, is_read`,
|
||||||
[senderId, recvId, message]
|
[senderId, recvId, message]
|
||||||
);
|
);
|
||||||
@@ -696,28 +696,25 @@ app.get('/api/interiors/:interiorId/definition', authenticate, async (req, res)
|
|||||||
|
|
||||||
// Начало копи
|
// Начало копи
|
||||||
app.post('/api/listen', authenticate, async (req, res) => {
|
app.post('/api/listen', authenticate, async (req, res) => {
|
||||||
|
console.log('Request data:', req.body);
|
||||||
const { player_id, json_filename } = req.body;
|
const { player_id, json_filename } = req.body;
|
||||||
console.log('Request data:', { player_id, json_filename }); // Добавьте в начало обработчика
|
|
||||||
if (!player_id || !json_filename) {
|
if (!player_id || !json_filename) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
error: 'player_id and json_filename are required'
|
error: 'player_id and json_filename are required'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log("Маму ебал этого сервера");
|
|
||||||
await virtualWorldPool.query(`
|
await virtualWorldPool.query(`
|
||||||
INSERT INTO json_listened (player_id, json_filename)
|
INSERT INTO json_listened (player_id, json_filename, listened_at)
|
||||||
VALUES ($1, $2)
|
VALUES ($1, $2, NOW())
|
||||||
`, [player_id, json_filename]);
|
`, [player_id, json_filename]);
|
||||||
|
|
||||||
res.status(200).json({ success: true });
|
res.status(200).json({ success: true });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Full DB error:', {
|
console.error('Full DB error:', err);
|
||||||
message: err.message,
|
|
||||||
stack: err.stack,
|
|
||||||
query: err.query // Если поддерживается вашим драйвером БД
|
|
||||||
});
|
|
||||||
res.status(500).json({
|
res.status(500).json({
|
||||||
success: false,
|
success: false,
|
||||||
error: 'Database operation failed',
|
error: 'Database operation failed',
|
||||||
|
|||||||
35
src/Game.js
35
src/Game.js
@@ -121,11 +121,11 @@ function Game({ avatarUrl, gender }) {
|
|||||||
}, [satiety, thirst]);
|
}, [satiety, thirst]);
|
||||||
|
|
||||||
|
|
||||||
const [currentDialog, setCurrentDialog] = useState(null);
|
//const [currentDialog, setCurrentDialog] = useState(null);
|
||||||
const [dialogIndex, setDialogIndex] = useState(0);
|
//const [dialogIndex, setDialogIndex] = useState(0);
|
||||||
const [showDialog, setShowDialog] = useState(false);
|
//const [showDialog, setShowDialog] = useState(false);
|
||||||
const [formData, setFormData] = useState({});
|
//const [formData, setFormData] = useState({});
|
||||||
const [currentForm, setCurrentForm] = useState(null);
|
//const [currentForm, setCurrentForm] = useState(null);
|
||||||
|
|
||||||
//Телефон
|
//Телефон
|
||||||
const scene = new THREE.Scene();
|
const scene = new THREE.Scene();
|
||||||
@@ -142,6 +142,20 @@ function Game({ avatarUrl, gender }) {
|
|||||||
const savedPositionRef = useRef(new THREE.Vector3());
|
const savedPositionRef = useRef(new THREE.Vector3());
|
||||||
const remotePlayersRef = useRef({});
|
const remotePlayersRef = useRef({});
|
||||||
|
|
||||||
|
|
||||||
|
const {
|
||||||
|
currentDialog,
|
||||||
|
dialogIndex,
|
||||||
|
showDialog,
|
||||||
|
formData,
|
||||||
|
currentForm,
|
||||||
|
loadDialog,
|
||||||
|
handleAnswerSelect,
|
||||||
|
handleFormSubmit,
|
||||||
|
handleFormChange,
|
||||||
|
setShowDialog
|
||||||
|
} = useDialogManager();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const id = setInterval(() => {
|
const id = setInterval(() => {
|
||||||
if (playerRef.current) {
|
if (playerRef.current) {
|
||||||
@@ -459,7 +473,7 @@ function Game({ avatarUrl, gender }) {
|
|||||||
cursor: 'pointer'
|
cursor: 'pointer'
|
||||||
};
|
};
|
||||||
|
|
||||||
const loadDialog = async (npcId) => {
|
/*const loadDialog = async (npcId) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/dialogs/${npcId}.json`);
|
const response = await fetch(`/dialogs/${npcId}.json`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
@@ -469,7 +483,7 @@ function Game({ avatarUrl, gender }) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Ошибка загрузки диалога:', error);
|
console.error('Ошибка загрузки диалога:', error);
|
||||||
}
|
}
|
||||||
};
|
};*/
|
||||||
const loader = new GLTFLoader();
|
const loader = new GLTFLoader();
|
||||||
// базовая геометрия для объектов типа "chair"
|
// базовая геометрия для объектов типа "chair"
|
||||||
const baseChairMesh = new THREE.Mesh(
|
const baseChairMesh = new THREE.Mesh(
|
||||||
@@ -580,7 +594,7 @@ function Game({ avatarUrl, gender }) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAnswerSelect = (answer) => {
|
/*const handleAnswerSelect = (answer) => {
|
||||||
if (answer.end) {
|
if (answer.end) {
|
||||||
setShowDialog(false);
|
setShowDialog(false);
|
||||||
} else if (answer.next !== undefined) {
|
} else if (answer.next !== undefined) {
|
||||||
@@ -627,7 +641,7 @@ function Game({ avatarUrl, gender }) {
|
|||||||
...prev,
|
...prev,
|
||||||
[name]: value
|
[name]: value
|
||||||
}));
|
}));
|
||||||
};
|
};*/
|
||||||
|
|
||||||
// Добавить функцию загрузки прогресса квестов:
|
// Добавить функцию загрузки прогресса квестов:
|
||||||
async function loadQuestsProgress() {
|
async function loadQuestsProgress() {
|
||||||
@@ -738,7 +752,7 @@ function Game({ avatarUrl, gender }) {
|
|||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
setMessages(data);
|
setMessages(data);
|
||||||
|
console.log('Сообщение загружено');
|
||||||
// Прокручиваем чат вниз
|
// Прокручиваем чат вниз
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const chatContainer = document.getElementById('chatContainer');
|
const chatContainer = document.getElementById('chatContainer');
|
||||||
@@ -774,6 +788,7 @@ function Game({ avatarUrl, gender }) {
|
|||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
setNewMessage("");
|
setNewMessage("");
|
||||||
|
console.log("Сообщение ушло");
|
||||||
// После отправки сразу обновляем сообщения
|
// После отправки сразу обновляем сообщения
|
||||||
loadMessages(activeChat.id);
|
loadMessages(activeChat.id);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user