@@ -13,12 +13,14 @@ import {
13
13
} from "./MessageDefinitions" ;
14
14
15
15
import libSource from "../ScriptEditor/NetscriptDefinitions.d.ts?raw" ;
16
+ import { saveObject } from "../SaveObject" ;
17
+ import { Player } from "@player" ;
16
18
17
19
function error ( errorMsg : string , { id } : RFAMessage ) : RFAMessage {
18
20
return new RFAMessage ( { error : errorMsg , id : id } ) ;
19
21
}
20
22
21
- export const RFARequestHandler : Record < string , ( message : RFAMessage ) => RFAMessage > = {
23
+ export const RFARequestHandler : Record < string , ( message : RFAMessage ) => RFAMessage | Promise < RFAMessage > > = {
22
24
pushFile : function ( msg : RFAMessage ) : RFAMessage {
23
25
if ( ! isFileData ( msg . params ) ) return error ( "Misses parameters" , msg ) ;
24
26
@@ -112,6 +114,22 @@ export const RFARequestHandler: Record<string, (message: RFAMessage) => RFAMessa
112
114
return new RFAMessage ( { result : libSource , id : msg . id } ) ;
113
115
} ,
114
116
117
+ getSaveFile : async function ( msg : RFAMessage ) : Promise < RFAMessage > {
118
+ const saveData = await saveObject . getSaveData ( ) ;
119
+ // We can't serialize the Uint8Array directly, so we convert every integer to a character and make a string out of the array
120
+ // The external editor can simply recreate the save by converting each char back to their char code
121
+ const converted =
122
+ typeof saveData === "string" ? saveData : saveData . reduce ( ( acc , cur ) => acc + String . fromCharCode ( cur ) , "" ) ;
123
+
124
+ return new RFAMessage ( {
125
+ result : {
126
+ identifier : Player . identifier ,
127
+ save : converted ,
128
+ } ,
129
+ id : msg . id ,
130
+ } ) ;
131
+ } ,
132
+
115
133
getAllServers : function ( msg : RFAMessage ) : RFAMessage {
116
134
const servers = GetAllServers ( ) . map ( ( { hostname, hasAdminRights, purchasedByPlayer } ) => ( {
117
135
hostname,
0 commit comments