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