Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telnet #120

Open
wants to merge 144 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 131 commits
Commits
Show all changes
144 commits
Select commit Hold shift + click to select a range
447bbcd
initial telnet
y4my4my4m Apr 29, 2023
81bf25c
interactivity
y4my4my4m Apr 29, 2023
a160303
parse ansi
y4my4my4m Apr 29, 2023
f4ed63c
disconnection
y4my4my4m Apr 29, 2023
81edb50
Negotiations
y4my4my4m Apr 29, 2023
b9e7cd0
Disconnect fix
y4my4my4m Apr 29, 2023
0ca6caa
Update
y4my4my4m Apr 29, 2023
8030b41
Fix
y4my4my4m Apr 29, 2023
b215d4f
Added TCPSocketSendString
y4my4my4m Apr 29, 2023
f775f9f
ansi parse
y4my4my4m Apr 29, 2023
0d05b08
SendTerminalType fix?
y4my4my4m Apr 30, 2023
b24fd9f
fix colors
y4my4my4m Apr 30, 2023
50eda1d
parses ASCII codes too
y4my4my4m Apr 30, 2023
8ad6968
input_skip buggy
y4my4my4m Apr 30, 2023
6cbfcab
fix
y4my4my4m Apr 30, 2023
6d61aca
update
y4my4my4m Apr 30, 2023
acd9d71
Update
y4my4my4m May 1, 2023
938ea9a
Colors
y4my4my4m May 1, 2023
08e0bf8
Colors functional
y4my4my4m May 1, 2023
7beb6c6
Keys
y4my4my4m May 1, 2023
f212ff5
fix
y4my4my4m May 1, 2023
c827979
cursor movement
y4my4my4m May 2, 2023
d15cc51
Update
y4my4my4m May 2, 2023
ba6f452
Cleaning
y4my4my4m May 2, 2023
62adc69
No_Input_test
y4my4my4m May 2, 2023
e766171
properly parsing ?25l ?25h code
y4my4my4m May 2, 2023
366c383
IsDigits
y4my4my4m May 2, 2023
38a2181
linemode
y4my4my4m May 4, 2023
3eafc9a
update
y4my4my4m May 8, 2023
989e452
Task input
y4my4my4m May 8, 2023
631712d
remove timeout
y4my4my4m May 8, 2023
889288c
fix
y4my4my4m May 8, 2023
263b800
update
y4my4my4m May 9, 2023
e32433a
update
y4my4my4m May 9, 2023
9665977
fix
y4my4my4m May 9, 2023
3f901db
BBS doesnt crash anymore
y4my4my4m May 9, 2023
31b7cfb
dont send any negotiation for now
y4my4my4m May 9, 2023
eb4bd2f
visual fix
y4my4my4m May 9, 2023
860702d
CursorMovement
y4my4my4m May 10, 2023
736ebce
moved TelnetURLs to it's own list
y4my4my4m May 10, 2023
34c740f
cleanup
y4my4my4m May 10, 2023
c1e8995
loop
y4my4my4m May 10, 2023
55ab847
cursor movement stable(r)
y4my4my4m May 10, 2023
c820e5b
Hf case
y4my4my4m May 10, 2023
b64d0bb
update
y4my4my4m May 10, 2023
4e8be47
cursor input support
y4my4my4m May 10, 2023
b3e1972
update
y4my4my4m May 10, 2023
e02c18b
disconnect
y4my4my4m May 10, 2023
7d9d6c4
centered window
y4my4my4m May 10, 2023
85b5eca
telnet cleanup
y4my4my4m May 11, 2023
56fc402
16 colors
y4my4my4m May 11, 2023
ccb1240
themes
y4my4my4m May 11, 2023
8afe183
16bit color extra support
y4my4my4m May 11, 2023
e27ec86
Cursor positioning works!!
y4my4my4m May 11, 2023
741c039
Send characters as you type
y4my4my4m May 11, 2023
4d883bb
Backspace
y4my4my4m May 11, 2023
4df07b6
Colors fixed?
y4my4my4m May 11, 2023
1203145
color fix 2?
y4my4my4m May 11, 2023
7407b25
update
y4my4my4m May 11, 2023
9d08a8f
Proper ESC key
y4my4my4m May 11, 2023
533159b
tab key
y4my4my4m May 11, 2023
ad1d9b0
Refactor
y4my4my4m May 11, 2023
ffd689d
colors fixed
y4my4my4m May 11, 2023
63f8828
cleanup
y4my4my4m May 11, 2023
c17f3af
Perma colored background
y4my4my4m May 11, 2023
06a7962
Fix
y4my4my4m May 11, 2023
b70946f
Fix
y4my4my4m May 11, 2023
35c6354
fix
y4my4my4m May 11, 2023
39cff33
cleanup and disable K
y4my4my4m May 11, 2023
77f0237
Telnet 32 ver
y4my4my4m May 12, 2023
df0b3be
telnet fix and telnet32 bgcolor
y4my4my4m May 13, 2023
7aa082e
Telnet display in it's own task
y4my4my4m May 13, 2023
dbdd3d5
fix
y4my4my4m May 13, 2023
84b0296
SplashScreen
y4my4my4m May 13, 2023
1e68c49
Fix
y4my4my4m May 13, 2023
a2b920f
ArtBrowser
y4my4my4m May 13, 2023
38d6cce
Main menu
y4my4my4m May 13, 2023
e93368a
Fix
y4my4my4m May 13, 2023
a65fd10
proper escape of dollar sign
y4my4my4m May 13, 2023
1286fe3
Fix
y4my4my4m May 13, 2023
532c10d
Dark mode toggle
y4my4my4m May 13, 2023
d0209a8
fix
y4my4my4m May 13, 2023
d47ce0b
Palette Fix
y4my4my4m May 13, 2023
75881a3
No need for DarkTemple palette
y4my4my4m May 13, 2023
1fe467a
removed syslog
y4my4my4m May 13, 2023
5862425
backspace fixed
y4my4my4m May 13, 2023
e231f7d
update
y4my4my4m May 14, 2023
fa14e6c
fix
y4my4my4m May 14, 2023
4aeb443
hold the connection and cursor less buggy
y4my4my4m May 14, 2023
b446622
SetPos (incomplete)
y4my4my4m May 14, 2023
f4cbd0e
DocMax
y4my4my4m May 14, 2023
d1fedf1
fix
y4my4my4m May 14, 2023
e2aeaa4
update
y4my4my4m May 16, 2023
3b497d9
telnet list
y4my4my4m May 17, 2023
97dfec4
Merge branch 'master' into telnet
y4my4my4m May 17, 2023
04d21a8
negotiation fix
y4my4my4m May 17, 2023
66ec1f6
fix
y4my4my4m May 17, 2023
ee9bf4f
case 'K'
y4my4my4m May 18, 2023
13921f5
ANSI Wallpaper
y4my4my4m May 19, 2023
fd86b7a
Default ANSI wallpaper
y4my4my4m May 19, 2023
9f2bef4
Added Telnet Sprite in Personal Menu
y4my4my4m May 19, 2023
46f4e5f
Revert menu
y4my4my4m May 19, 2023
aa1e541
Menu Sprite Icon moved to Telnet's Extras
y4my4my4m May 19, 2023
f9565c6
Renamed to WallPaperDolDoc
y4my4my4m May 19, 2023
b9c136a
Wallpapers
y4my4my4m May 19, 2023
7e73569
Correct colors Palette
y4my4my4m May 20, 2023
7cf40ea
Update
y4my4my4m May 22, 2023
934a6c8
remove/update wallpapers
y4my4my4m May 22, 2023
dd34198
fix
y4my4my4m May 23, 2023
13fb4e8
ctrl to alt keys
y4my4my4m May 25, 2023
c7ccedb
splashscreen update for alt+n
y4my4my4m May 25, 2023
34177b0
Fixed disconnect crash/loop
y4my4my4m May 25, 2023
d040f99
skynet
y4my4my4m Aug 14, 2023
f8ac780
skynet gpt4
y4my4my4m Aug 14, 2023
f4cf93c
Uses the JSON util
y4my4my4m Aug 24, 2023
85fe748
freeing memory
y4my4my4m Aug 24, 2023
fe04a34
Updates
y4my4my4m Aug 24, 2023
1b112b9
Fix conflict
y4my4my4m Aug 24, 2023
eff3984
Merge branch 'master' into telnet
y4my4my4m Aug 24, 2023
9f04a75
example ansi art
y4my4my4m Aug 24, 2023
78ad945
Merge branch 'telnet' of github.com:Zeal-Operating-System/ZealOS into…
y4my4my4m Aug 24, 2023
4100811
Lock telnet cursor to prevent messing up print
y4my4my4m Aug 24, 2023
090bc4b
move TelnetGr version in the Extra folder
y4my4my4m Aug 24, 2023
21f1cc9
nginx middleware server
y4my4my4m Aug 24, 2023
4a93b3f
Add desktop feature
y4my4my4m Aug 24, 2023
7ac5f55
Rename
y4my4my4m Aug 24, 2023
f8c0032
removed heavy .ans file
y4my4my4m Aug 24, 2023
8a3fb09
Added missing file
y4my4my4m Aug 24, 2023
d4e94ff
rename
y4my4my4m Aug 24, 2023
64bf5c5
indent
y4my4my4m Aug 24, 2023
0a518e2
NetLogTogglable
y4my4my4m Aug 24, 2023
a5a4548
NetToggle and WallPaper Stats
y4my4my4m Aug 24, 2023
be3ca8f
Seperate features in different PRs
y4my4my4m Aug 25, 2023
2c280d0
Update Tradition.ZC
y4my4my4m Aug 25, 2023
d098189
Update PaletteEdit.ZC
y4my4my4m Aug 25, 2023
02497b0
Update Tradition.ZC
y4my4my4m Aug 25, 2023
931d057
Update Tradition.ZC
y4my4my4m Aug 25, 2023
fd716e9
Update Tradition.ZC
y4my4my4m Aug 25, 2023
33c0eed
Merge branch 'telnet' of github.com:Zeal-Operating-System/ZealOS into…
y4my4my4m Aug 25, 2023
727e7ac
Update ConversionScript.ZC
y4my4my4m Aug 25, 2023
5e701f6
Merge branch 'master' into telnet
y4my4my4m Nov 27, 2023
1e84ede
Merge branch 'master' into telnet
y4my4my4m Dec 19, 2023
f409217
update
y4my4my4m Dec 22, 2023
b08af23
Merge branch 'master' into telnet
GutPuncher Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/Demo/Graphics/WallPaperDolDoc.ZC
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
U0 (*old_wall_paper)(CTask *task);
CDoc *wallpaper_doc;

RegDefault("Wallpapers/Current", "1;\n");
RegExe("Wallpapers/Current");

U0 WallPaperSet(I8 direction) {
CDirEntry *tmpde1;
// read the current wallpaper index from the registry
I64 current = RegExe("Wallpapers/Current");
I64 max = 0;

// SysLog("Reading current wallpaper index from registry: %d\n", current);

// search the wallpapers directory for .DD files
tmpde1 = FilesFind("~/Wallpapers/1024/*.DD", 1);
if (tmpde1) {
do {
max++;
tmpde1 = tmpde1->next;
} while (tmpde1);
}

// move to the next/previous wallpaper
current += direction;
if (current < 1)
current = max; // wrap around to the end
if (current > max)
current = 1; // wrap around to the start

// write the new current index back to the registry
RegWrite("Wallpapers/Current", "%d;\n", current);

// SysLog("Current: %d\n", current);
// Change the wallpaper
Sys("WallPaperDolDocInit(\"~/Wallpapers/1024/%d.DD\");\n", current);
}


U0 WallPaperDolDocInit(I64 filepath="::/Home/Wallpapers/Default.DD")
{
if (Fs != sys_task)
{
"\nMust be System Included. (SHIFT-F5 / RightClick->System Include) \n";
return;
}
old_wall_paper = gr.fp_wall_paper;
wallpaper_doc = DocRead(filepath, DOCF_DBL_DOLLARS | DOCF_NO_CURSOR);

sys_winmgr_task->display_doc = wallpaper_doc;
DocCursor(OFF, wallpaper_doc);

// if (gr_palette[0] > gr_palette[15])
// Fs->text_attr = WHITE << 4 + WHITE;
// else
// Fs->text_attr = BLACK << 4 + BLACK;


wallpaper_doc->win_task = sys_winmgr_task;

// gr.fp_wall_paper = &WallPaperDD;
}
51 changes: 51 additions & 0 deletions src/Home/Net/Programs/Skynet/HowToHost.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// This is an NGINX reverse proxy configuration file for the Skynet Middleware

server {
// set whatever port you'd like
listen 9000;
// replace the server name with yours
server_name skynet.middleware.com;

# Custom log locations
access_log /var/log/nginx/skynet_access.log;
error_log /var/log/nginx/skynet_error.log;

location /gpt3 {
proxy_pass https://api.openai.com/v1/completions; # GPT-3 endpoint

# Required for SSL verification with the upstream server (OpenAI)
proxy_ssl_server_name on;
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
proxy_ssl_session_reuse off;

# Headers for OpenAI
// replace the sk-XXXX with your API key
proxy_set_header Authorization "Bearer sk-XXXX";
proxy_set_header Content-Type "application/json";

# Standard proxy headers
proxy_set_header Host api.openai.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /chat {
proxy_pass https://api.openai.com/v1/chat/completions; # ChatGPT endpoint

# Required for SSL verification with the upstream server (OpenAI)
proxy_ssl_server_name on;
proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
proxy_ssl_session_reuse off;

# Headers for OpenAI
// replace the sk-XXXX with your API key
proxy_set_header Authorization "Bearer sk-XXXX";
proxy_set_header Content-Type "application/json";

# Standard proxy headers
proxy_set_header Host api.openai.com;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

}
170 changes: 170 additions & 0 deletions src/Home/Net/Programs/Skynet/Skynet.ZC
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#define SERVER_ADDR "skynet.middleware.com"
#define SERVER_PORT 9000
#define INITIAL_BUF_SIZE 2048
#define DEFAULT_SYSTEMPROMPT "You are a helpful assistant but roleplay as skynet from Terminator."
#include "::/Home/Net/Utilities/JSON/JSON"
class Message {
U8 role[10]; // "user" or "assistant"
U8 content[1024];
} history[100];
I64 currentHistoryCount = 0;

U0 AppendToHistory(U8 *role, U8 *content) {
if (currentHistoryCount < 100) {
StrCopy(history[currentHistoryCount].role, role);
StrCopy(history[currentHistoryCount].content, content);
currentHistoryCount++;
}
}

U8 *StrChr(U8 *Str,U8 Pivot)
{
//U8 *Orig=Str;
while (*Str!=Pivot&&*Str!=0)Str++;
if (*Str==Pivot) return Str;
else return 0;
}
U8* RemoveBeforeJSON(U8 *input) {
U8 *jsonStart = StrChr(input, '{');

if (jsonStart != NULL) {
return jsonStart;
}
return NULL; // No JSON detected
}

I64 Skynet(U8 *message, U8 *system, U8 *model)
{
I64 sock, index, bufferSize = INITIAL_BUF_SIZE;
U8 *responseBuf = MAlloc(bufferSize); // Dynamic allocation of the buffer

sock = TCPConnectionCreate(SERVER_ADDR, SERVER_PORT);
if (sock <= 0)
{
PrintErr("Failed to connect to middleware server");
return sock;
}

U8 *messages = StrPrint(NULL, "{\"role\": \"system\",\"content\": \"%s\"},", system);

for (index = 0; index < currentHistoryCount; index++) {
U8 *msg = StrPrint(NULL, "{\"role\": \"%s\",\"content\": \"%s\"},", history[index].role, history[index].content);
messages = CatPrint(messages, msg);
Free(msg);
}

U8 *currentUserMsg = StrPrint(NULL, "{\"role\": \"user\",\"content\": \"%s\"}", message);
messages = CatPrint(messages, currentUserMsg);
Free(currentUserMsg);

U8 *payload = StrPrint(NULL, "{\"model\": \"%s\",\"messages\": [%s]}", model, messages);
Free(messages);

//SysLog(payload);

U8 *requestHeader = StrPrint(NULL,
"POST /chat HTTP/1.1\r\n"
"Host: %s:%d\r\n"
"User-Agent: ZealOSClient/1.0\r\n"
"Accept: */*\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n"
"\r\n",
SERVER_ADDR,
SERVER_PORT,
StrLen(payload)
);

U8 *fullRequest = StrPrint(NULL, "%s%s", requestHeader, payload);
TCPSocketSendString(sock, fullRequest);

Free(requestHeader);
Free(payload);
Free(fullRequest);

I64 responseLength = TCPSocketReceive(sock, responseBuf, bufferSize - 1);
responseBuf[responseLength] = 0; // Null-terminate the buffer for safety

if (responseLength == sizeof(responseBuf) - 1) {
PrintErr("Warning: responseBuf might be full. Some data could be truncated.");
}
// Check if buffer might be full
while (responseLength == bufferSize - 1)
{
// Double the buffer size and reallocate
bufferSize *= 2;
Free(responseBuf);
responseBuf = MAlloc(bufferSize);

// Continue receiving data from where you left off
responseLength += TCPSocketReceive(sock, responseBuf + responseLength, bufferSize - responseLength - 1);
responseBuf[responseLength] = 0;
}
//SysLog(responseBuf);

CCompCtrl *cc = CompCtrlNew(MStrPrint("%s", RemoveBeforeJSON(responseBuf)));
CJSONDataEntry *jsonData = JSONParse(cc);

// Retrieve the 'choices' array
CJSONDataEntry *choicesEntry = JSONKeyValueGet(jsonData, "choices");
if (!choicesEntry || choicesEntry->type != JSONT_ARRAY) {
// Handle error: choices key not found or not an array
return;
}

// Retrieve the first object from the 'choices' array
CJSONDataEntry *firstChoice = JSONIndexValueGet(choicesEntry, 0);
if (!firstChoice || firstChoice->type != JSONT_OBJ) {
// Handle error: First choice not found or not an object
return;
}

// Retrieve the 'message' object from the first choice
CJSONDataEntry *messageEntry = JSONKeyValueGet(firstChoice, "message");
if (!messageEntry || messageEntry->type != JSONT_OBJ) {
// Handle error: message key not found or not an object
return;
}

// Retrieve the 'content' string from the 'message' object
CJSONDataEntry *contentEntry = JSONKeyValueGet(messageEntry, "content");
if (!contentEntry || contentEntry->type != JSONT_STRING) {
// Handle error: content key not found or not a string
return;
}

U8 *completion = contentEntry->string_data;
//SysLog(completion);
CompCtrlDel(cc);

"\n$$RED$$ Skynet: $$YELLOW$$%s$$FG$$\n", completion;

AppendToHistory("user", message);
AppendToHistory("assistant", completion);

TCPSocketClose(sock);
Free(responseBuf);
return 0;
}

// gpt-3.5-turbo || gpt-4
public U0 ChatUI(U8 *system=DEFAULT_SYSTEMPROMPT, U8 *model="gpt-4") {
U8 *userInput;
DocClear;

try{
"\t\t\t\t\t\t\t$$LTRED$$Welcome to Skynet$$FG$$\n";

while(1) {
"\n$$LTBLUE$$ You: $$GREEN$$";

LBts(&Fs->task_flags, TASKf_CMD_LINE_PROMPT);
userInput = StrGet(,, SGF_SHIFT_ESC_EXIT);
LBtr(&Fs->task_flags, TASKf_CMD_LINE_PROMPT);
Skynet(userInput, system, model);
}
}
catch
PutExcept;
}
ChatUI;
72 changes: 72 additions & 0 deletions src/Home/Net/Programs/Skynet/Skynet3.ZC
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#define SERVER_ADDR "skynet.middleware.com"
#define SERVER_PORT 9000

U8* ExtractGPTCompletion(U8 *response) {
U8 *start = StrFind("\"text\": \"", response);
if (!start) {
return NULL; // Pattern not found
}

start += 10; // Move pointer after '"text": "'

U8 *end = StrFind("\",", start); // Find the closing double quote
if (!end) {
return NULL;
}

*end = 0; // Null terminate the completion string

return start;
}

public I64 Skynet3(U8 *prompt)
{
U8 responseBuf[8192];
I64 sock;

sock = TCPConnectionCreate(SERVER_ADDR, SERVER_PORT);
if (sock <= 0)
{
PrintErr("Failed to connect to middleware server");
return sock;
}

U8 *payload = StrPrint(NULL, "{\"model\": \"text-davinci-003\",\"prompt\": \"%s\",\"max_tokens\": 100,\"temperature\": 1}", prompt);
U8 *requestHeader = StrPrint(NULL,
"POST /gpt3 HTTP/1.1\r\n"
"Host: %s:%d\r\n"
"User-Agent: ZealOSClient/1.0\r\n"
"Accept: */*\r\n"
"Content-Type: application/json\r\n"
"Content-Length: %d\r\n"
"\r\n",
SERVER_ADDR,
SERVER_PORT,
StrLen(payload)
);
U8 *fullRequest = StrPrint(NULL, "%s%s\n\n", requestHeader, payload);

TCPSocketSendString(sock, fullRequest);
Free(requestHeader);
Free(payload);
Free(fullRequest);


I64 responseLength = TCPSocketReceive(sock, responseBuf, sizeof(responseBuf) - 1); // -1 to ensure space for null terminator

responseBuf[responseLength] = 0; // Null-terminate the response

// Assuming the headers and payload are separated by two newline sequences (standard HTTP)
U8 *jsonPayload = StrFind("\r\n\r\n", responseBuf);
if (!jsonPayload) {
TCPSocketClose(sock);
return -1; // or some error code
}
jsonPayload += 4; // Move past the header separator

U8 *completion = ExtractGPTCompletion(jsonPayload);
Print("$$RED$$Skynet: $$YELLOW$$%s$$FG$$\n", completion);

TCPSocketClose(sock);
return 0;
}
Loading