Skip to content

Commit

Permalink
you are in a maze of twisty little menus, all alike.
Browse files Browse the repository at this point in the history
  • Loading branch information
francinum committed Jan 5, 2025
1 parent badf077 commit 501631c
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 17 deletions.
30 changes: 30 additions & 0 deletions WorkInProgress/francinum/cphones_new/_defines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,36 @@
/// A high level 'group' of verbs
#define PACKET_FIELD_PROTOCOL "proto"
#define PACKET_PROTOCOL_SIP "sip"
// ----REGISTRATION----
#define PACKET_SIP_VERB_REGISTER "register"
#define PACKET_SIP_FIELD_USER "user"
#define PACKET_SIP_FIELD_REGISTER_SECRET "auth"
#define PACKET_SIP_VERB_REAUTH "reauth"
#define PACKET_SIP_FIELD_AUTH_TOKEN "auth_token"
#define PACKET_SIP_VERB_ACKNOWLEDGE "ack"
//shares PACKET_SIP_FIELD_AUTH_TOKEN
#define PACKET_SIP_VERB_NEGATIVE_ACKNOWLEDGE "nack"
#define PACKET_SIP_FIELD_NACK_CAUSE "cause"
#define PACKET_SIP_NACK_CAUSE_BAD_SECRET "badsecret"

// ----CALL CONTROL----
#define PACKET_SIP_FIELD_CALLID "call-id"
#define PACKET_SIP_VERB_INVITE "invite"
/// Sender
#define PACKET_SIP_INVITE_FIELD_FROM "from"
/// Invite recipient number.
#define PACKET_SIP_INVITE_FIELD_TO "to"
#define PACKET_SIP_VERB_SESSION "session"
#define PACKET_SIP_SESSION_
#define PACKET_PROTOCOL_RTP "rtp"


// SIP State values
#define SIP_STATE_CODE 1 //List Index
#define SIP_STATE_CODE_START_RINGING 1 //No data
#define SIP_STATE_CODE_STOP_RINGING 2 //No data
#define SIP_STATE_TERMINATE 3 // data: Cause Code
#define SIP_STATE_REG_FAILURE 4 //No data
#define SIP_STATE_DATA 2 //List Index

#error HEY DIPSHIT TEAR OUT A LOT OF YOUR SHIT AND IMPLIMENT STATUS CODES INSTEAD OF SHITTING YOURSELF LIKE A MONKEY

Check failure on line 45 in WorkInProgress/francinum/cphones_new/_defines.dm

View workflow job for this annotation

GitHub Actions / Run Linters

#error HEY DIPSHIT TEAR OUT A LOT OF YOUR SHIT AND IMPLIMENT STATUS CODES INSTEAD OF SHITTING YOURSELF LIKE A MONKEY
31 changes: 29 additions & 2 deletions WorkInProgress/francinum/cphones_new/extensions_info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ list(

// signal protocol

// Skeleton:
{
"proto":"sip",
"verb": VERB,
"seq": $RAND_SEQ // Used to associate ACKs with various flows. - NOT ANYMORE THIS IS ANNOYING
}

//Verbs:
/*
* REGISTER: Grants a reauth token upon login, allows placing calls via INVITE
* REAUTH: like register, returns a new auth token (via ACK) upon successful reauth, else NACK
* INVITE: Request to start a call with another extension.
* RINGING: Informs the station that the far side is now ringing.
* CANCEL: Sent by the requesting client. Cancel the call, free all equipment.
*
*/

// Registration
user send:
{
"proto":"sip",
Expand All @@ -28,13 +46,22 @@ exchange reply:
"proto":"sip",
"verb":"ack",
"user":"$EXTNUM",
"reg_token":"$token",
"auth_token":"$token",
}


//keepalive, Intentionally doesn't include password.
//keepalive, Use the auth token instead.
{
"proto":"sip",
"verb":"reauth",
"user":"$EXTNUM",
"auth_token":"$REAUTHTOKEN",
}

// Start Call
{
"proto":"sip",
"verb": "invite",
"to" : "$EXT",
"auth_token":"$token",
}
19 changes: 19 additions & 0 deletions WorkInProgress/francinum/cphones_new/phone/_packet_handler.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,23 @@
*
* We're just gonna trust this is only ever being called by the master,
* if it's not, go fuck yourself. seriously.
*
* Standard packet output function:
* receive_handler_packet(datum/packet_handler/sender, datum/signal/signal)
*
* Other handlers may define more required functions.
*/

/obj/machinery/proc/receive_handler_packet(datum/packet_handler/sender, /datum/signal/signal, ...)
return

/datum/packet_handler/New(_master)
. = ..()
master = _master

/datum/packet_handler/Destroy(force, ...)
master = null
return ..()

/datum/packet_handler/process(delta_time)
return
30 changes: 22 additions & 8 deletions WorkInProgress/francinum/cphones_new/phone/phone.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
/// Used to authenticate with the exchange.
var/tmp/autoconf_secret = ""

/// Set to TRUE once the SIP core has fully booted.
var/tmp/net_booted = FALSE

/// Is our write-protect screw installed? If not, Allow entering configuration mode.
var/config_screwed = TRUE
/// Are we currently in the config handler? If so, what state are we in.
Expand All @@ -43,7 +40,7 @@
packet_queue = list()
packet_handlers = list()
//Init our various handlers.
packet_handlers[PACKET_HANDLER_VOICE_DATA] = new /datum/packet_handler/voice_data()
packet_handlers[PACKET_HANDLER_VOICE_DATA] = new /datum/packet_handler/voice_data(src, /*speaker*/)

/obj/machinery/telephony/telephone/Destroy()
. = ..()
Expand All @@ -59,13 +56,16 @@


/obj/machinery/telephony/telephone/process()
// We have not 'booted'
if(packet_handlers[PACKET_HANDLER_SIGNALLING])
// We intentionally delay this until game start.
if(!packet_handlers[PACKET_HANDLER_SIGNALLING])
packet_handlers[PACKET_HANDLER_SIGNALLING] = new /datum/packet_handler/sip_registration(
src,
init_extension,
init_office_code,
autoconf_secret
)
else
packet_handlers[PACKET_HANDLER_SIGNALLING].process()
if(length(packet_queue))
handle_packet_queue()

Expand All @@ -75,8 +75,17 @@
var/datum/signal/storable = signal.Copy()
packet_queue += storable

/obj/machinery/telephony/telephone

/obj/machinery/telephony/telephone/receive_handler_packet(datum/packet_handler/sender, datum/signal/signal, list/sip_state)
switch(sender.type)
if(/datum/packet_handler/sip_registration)
//SIP data handler can also send control information instead, it'll only send one or the other.
if(sip_state)
switch(sip_state[SIP_STATE_CODE])
if(SIP_STATE_CODE_START_RINGING)
else
if(/datum/packet_handler/voice_data)

// time to play dress-up as a subsystem
/obj/machinery/telephony/telephone/proc/handle_packet_queue()
for(var/datum/signal/packet as anything in packet_queue)
var/list/data = packet.data
Expand All @@ -86,3 +95,8 @@
if(PACKET_PROTOCOL_RTP)
packet_handlers[PACKET_HANDLER_VOICE_DATA].receive_signal(packet)
//else {drop_packet};
if(data[PACKET_CMD] == NET_COMMAND_PING_REPLY) //If this is a ping reply, it also goes to the SIP handler.
packet_handlers[PACKET_HANDLER_SIGNALLING]?.receive_signal(packet)
packet_queue -= packet
if(TICK_CHECK)
return
73 changes: 73 additions & 0 deletions WorkInProgress/francinum/cphones_new/phone/sip_call.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Holds state about an individual SIP call.

/datum/sip_call

/// The controlling SIP handler.
var/datum/sip_handler/owner

/// Are we originating this call?
/// Behaviour basically flips if this is false.
var/originating = TRUE

/// Randomly generated call ID. Used for tracing and for identification. md5(world.time+ref(src))
var/call_id

/// ORIGINATE: The number we are calling.
/// ANSWER: The number calling us.
var/calling_number

var/our_number

/// Server address
var/target_addr

/* Call Setup */
/// ORIGINATE: Call is being set up, Play no comfort noises. If timeout, cancel and terminate self.
#define CALLSTATE_SETUP 0
/// ORIGINATE: Far side is ringing, play ringback.
/// ANSWER: We are ringing, Instruct the phone to start ringing.
#define CALLSTATE_RINGING 1


/// We are talking, Stop noises, instruct the SIP handler to get everything ready for audio.
#define CALLSTATE_TALKING 2

/* Call Teardown/Error */
/// The connection was closed, check cause_code and go from there.
#define CALLSTATE_TERMINATE 3

/// Current call state.
var/state = 0

/// Q.850 Cause Code (Beats coming up with my own system) for which our call was terminated.
var/cause_code

/datum/sip_call/New(_master, _our_number, _calling_number, _target_addr, _call_id)
. = ..()
call_id = _call_id || md5("[world.time][ref(src)]")
our_number = _our_number
calling_number = _calling_number
target_addr = _target_addr
if(_call_id)
// Being supplied a call ID means we are NOT originating.
originating = FALSE

/datum/sip_call/receive_signal(datum/signal/signal)
. = ..()

//
/datum/sip_call/proc/place_call(destination = calling_number)
if(!calling_number)
calling_number = destination
var/datum/signal/invite = new(
null,
list(
PACKET_DESTINATION_ADDRESS = target_addr,
PACKET_FIELD_PROTOCOL = PACKET_PROTOCOL_SIP,
PACKET_FIELD_VERB = PACKET_SIP_VERB_INVITE,
PACKET_SIP_INVITE_FIELD_FROM = our_number,
PACKET_SIP_INVITE_FIELD_TO = calling_number,
PACKET_SIP_FIELD_CALLID = call_id
)
)
return invite
Loading

0 comments on commit 501631c

Please sign in to comment.