%juice-box
%v0.1
%by: templest d azmitia
import GUI
View.Set ("graphics:400;300,title:juice-box v0.1,nobuttonbar")
GUI.SetBackgroundColor (gray)
var input, output, font, font_bold, dummy_buffer, connection, file : int
var dummy_buffer_str, name : string
var port_list : array 1 .. 120 of int
font := Font.New ("verdana:8")
font_bold := Font.New ("verdana:8:bold")
dummy_buffer := 7200
for i : 1 .. 120
port_list (i) := dummy_buffer
dummy_buffer := dummy_buffer + 1
end for
name := "user"
proc getname
open : file, "config.ini", get
loop
exit when eof (file)
get : file, dummy_buffer_str : *
if length (dummy_buffer_str) > 5 and dummy_buffer_str (1 .. 5) = "name:" then
name := dummy_buffer_str (6 .. *)
end if
end loop
close : file
end getname
getname
proc changename (new_name : string)
dummy_buffer := 1
open : file, "config.ini", put, mod, seek
loop
exit when eof (file)
get : file, dummy_buffer_str : *
if length (dummy_buffer_str) > 5 and dummy_buffer_str (1 .. 5) = "name:" then
seek : file, (dummy_buffer)
put : file, "name:" + new_name
getname
exit
end if
dummy_buffer := dummy_buffer + 1
end loop
close : file
end changename
connection := 0
proc connect (address : string)
GUI.AddLine (output, "** Please wait while connecting... **")
for r : 1 .. 120
connection := Net.OpenConnection (address, port_list (r))
if connection > 0 then
exit
end if
end for
if connection < 0 then
%connection not established msg goes here
GUI.AddLine (output, "** Connection to '" + address + "' failed **")
GUI.AddLine (output, Error.LastMsg)
GUI.AddLine (output, "")
else
%connection establish msg goes here
GUI.AddLine (output, "** Connection to '" + address + "' has been established**")
end if
end connect
proc input_string (msg : string)
%processing of input goes in here
if msg = "!quit" then
GUI.Quit
elsif length (msg) > 9 and msg (1 .. 8) = "!connect" then
dummy_buffer_str := msg (10 .. *)
connect (dummy_buffer_str)
elsif length (msg) > 6 and msg (1 .. 5) = "!name" then
dummy_buffer_str := msg (7 .. *)
changename (dummy_buffer_str)
else
GUI.AddLine (output, name + " says: " + msg)
if connection > 0 then
put : connection, name + " says: " + msg
end if
end if
GUI.SetText (input, "")
end input_string
input := GUI.CreateTextFieldFull (10, 10, maxx - 20, "", input_string, GUI.INDENT, font, 0)
output := GUI.CreateTextBoxFull (10, 35, maxx - 20, maxy - 45, GUI.INDENT, font)
loop
exit when GUI.ProcessEvent
end loop
|