File size: 3,586 Bytes
62ec639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a725021
 
 
 
 
 
e937b48
62ec639
 
 
 
 
 
 
a725021
62ec639
 
 
 
 
 
 
a725021
62ec639
a725021
 
 
62ec639
a725021
 
62ec639
a725021
 
62ec639
a725021
 
 
 
 
 
 
 
 
 
 
62ec639
a725021
 
 
62ec639
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a725021
 
62ec639
 
 
 
 
 
 
 
 
 
a725021
62ec639
 
e937b48
a725021
 
62ec639
 
a725021
62ec639
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
// DOM Elements
const elements = {
    authSection: document.getElementById('auth-section'),
    botSection: document.getElementById('bot-section'),
    output: document.getElementById('output'),
    status: document.getElementById('connection-status'),
    loginBtn: document.getElementById('login-btn'),
    registerBtn: document.getElementById('register-btn'),
    deployBtn: document.getElementById('deploy-btn'),
    commandInput: document.getElementById('command-input'),
    sendCommand: document.getElementById('send-command'),
    themeToggle: document.getElementById('theme-toggle'),
    musicToggle: document.getElementById('music-toggle'),
    videoElement: document.getElementById('funk-video')
};

// State
let currentUser = null;
let isMusicPlaying = false;
let isDarkMode = true;

// Funk/Phunk videos
const funkVideos = [
    "https://example.com/funk1.mp4",
    "https://example.com/funk2.mp4",
    "https://example.com/phunk1.mp4"
];

// Initialize Socket.io with robust settings
const socket = io({
    reconnection: true,
    reconnectionAttempts: Infinity,
    reconnectionDelay: 1000,
    timeout: 20000
});

// 1. Force terminal visibility on load
window.addEventListener('load', () => {
    elements.botSection.style.display = 'block';
    elements.authSection.style.display = 'none';
    updateStatus('System loaded');
    playRandomVideo();
});

// 2. Play random funk video
function playRandomVideo() {
    const randomVideo = funkVideos[Math.floor(Math.random() * funkVideos.length)];
    elements.videoElement.src = randomVideo;
    elements.videoElement.play().catch(e => console.log("Video play error:", e));
    elements.videoElement.onended = playRandomVideo;
}

// 3. Connection monitoring
function updateStatus(message, isError = false) {
    elements.status.textContent = message;
    elements.status.style.background = isError ? '#e74c3c' : '#2ecc71';
    appendToOutput(message, isError ? 'error' : 'info');
}

// 4. Socket event handlers
socket.on('connect', () => {
    updateStatus('Connected to server');
    socket.emit('terminal-ready');
});

socket.on('disconnect', () => {
    updateStatus('Disconnected', true);
});

socket.on('connect_error', (err) => {
    updateStatus(`Connection error: ${err.message}`, true);
});

socket.on('terminal-output', (data) => {
    appendToOutput(data, 'output');
});

socket.on('terminal-init', (data) => {
    appendToOutput(`Terminal initialized at ${new Date().toLocaleTimeString()}`, 'success');
});

// 5. Append to terminal
function appendToOutput(text, type = 'output') {
    const line = document.createElement('div');
    line.className = type;
    line.textContent = text;
    elements.output.appendChild(line);
    elements.output.scrollTop = elements.output.scrollHeight;
}

// 6. Command handling
elements.sendCommand.addEventListener('click', sendCommand);
elements.commandInput.addEventListener('keypress', (e) => {
    if (e.key === 'Enter') sendCommand();
});

function sendCommand() {
    const command = elements.commandInput.value.trim();
    if (!command) return;
    
    appendToOutput(`$ ${command}`, 'command');
    socket.emit('terminal-command', { command, userId: currentUser });
    elements.commandInput.value = '';
}

// 7. Fallback: If no connection after 5 seconds
setTimeout(() => {
    if (elements.output.children.length === 0) {
        appendToOutput('Running in offline mode. Some features may be limited.', 'warning');
    }
}, 5000);

// 8. Force terminal visibility (redundant check)
setInterval(() => {
    elements.botSection.style.display = 'block';
}, 3000);