mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-12-12 06:14:09 +01:00
tweak(sessionmanager/rdr3): onesync support
This commit is contained in:
@@ -10,18 +10,19 @@ function assignSlotId() {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
let hostIndex = -1;
|
let hostIndex = -1;
|
||||||
|
const isOneSync = GetConvar("onesync", "off") !== "off";
|
||||||
|
|
||||||
protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", function(err, root) {
|
protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", function(err, root) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RpcMessage = root.lookupType("rline.RpcMessage");
|
const RpcMessage = root.lookupType("rline.RpcMessage");
|
||||||
const RpcResponseMessage = root.lookupType("rline.RpcResponseMessage");
|
const RpcResponseMessage = root.lookupType("rline.RpcResponseMessage");
|
||||||
const InitSessionResponse = root.lookupType("rline.InitSessionResponse");
|
const InitSessionResponse = root.lookupType("rline.InitSessionResponse");
|
||||||
@@ -52,7 +53,7 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
function emitSessionCmds(target, cmd, cmdname, msg) {
|
function emitSessionCmds(target, cmd, cmdname, msg) {
|
||||||
const stuff = {};
|
const stuff = {};
|
||||||
stuff[cmdname] = msg;
|
stuff[cmdname] = msg;
|
||||||
|
|
||||||
emitMsg(target, RpcMessage.encode({
|
emitMsg(target, RpcMessage.encode({
|
||||||
Header: {
|
Header: {
|
||||||
MethodName: 'scmds'
|
MethodName: 'scmds'
|
||||||
@@ -79,26 +80,30 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
function emitAddPlayer(target, msg) {
|
function emitAddPlayer(target, msg) {
|
||||||
emitSessionCmds(target, 2, 'AddPlayer', msg);
|
emitSessionCmds(target, 2, 'AddPlayer', msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitRemovePlayer(target, msg) {
|
function emitRemovePlayer(target, msg) {
|
||||||
emitSessionCmds(target, 3, 'RemovePlayer', msg);
|
emitSessionCmds(target, 3, 'RemovePlayer', msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
function emitHostChanged(target, msg) {
|
function emitHostChanged(target, msg) {
|
||||||
emitSessionCmds(target, 5, 'HostChanged', msg);
|
emitSessionCmds(target, 5, 'HostChanged', msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
onNet('playerDropped', () => {
|
onNet('playerDropped', () => {
|
||||||
|
if (isOneSync) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const oData = playerDatas[source];
|
const oData = playerDatas[source];
|
||||||
delete playerDatas[source];
|
delete playerDatas[source];
|
||||||
|
|
||||||
if (oData && hostIndex === oData.slot) {
|
if (oData && hostIndex === oData.slot) {
|
||||||
const pda = Object.entries(playerDatas);
|
const pda = Object.entries(playerDatas);
|
||||||
|
|
||||||
if (pda.length > 0) {
|
if (pda.length > 0) {
|
||||||
hostIndex = pda[0][1].slot | 0; // TODO: actually use <=31 slot index *and* check for id
|
hostIndex = pda[0][1].slot | 0; // TODO: actually use <=31 slot index *and* check for id
|
||||||
|
|
||||||
for (const [ id, data ] of Object.entries(playerDatas)) {
|
for (const [ id, data ] of Object.entries(playerDatas)) {
|
||||||
emitHostChanged(id, {
|
emitHostChanged(id, {
|
||||||
index: hostIndex
|
index: hostIndex
|
||||||
@@ -108,15 +113,15 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
hostIndex = -1;
|
hostIndex = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oData) {
|
if (!oData) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oData.slot > -1) {
|
if (oData.slot > -1) {
|
||||||
slotsUsed &= ~(1 << oData.slot);
|
slotsUsed &= ~(1 << oData.slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [ id, data ] of Object.entries(playerDatas)) {
|
for (const [ id, data ] of Object.entries(playerDatas)) {
|
||||||
emitRemovePlayer(id, {
|
emitRemovePlayer(id, {
|
||||||
id: oData.id
|
id: oData.id
|
||||||
@@ -127,7 +132,7 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
console.log(e.stack);
|
console.log(e.stack);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function makeResponse(type, data) {
|
function makeResponse(type, data) {
|
||||||
return {
|
return {
|
||||||
Header: {
|
Header: {
|
||||||
@@ -147,34 +152,36 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
}*/
|
}*/
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async InitPlayer2(source, data) {
|
async InitPlayer2(source, data) {
|
||||||
const req = InitPlayer2_Parameters.decode(data);
|
const req = InitPlayer2_Parameters.decode(data);
|
||||||
|
|
||||||
playerDatas[source] = {
|
if (!isOneSync) {
|
||||||
gh: req.gh,
|
playerDatas[source] = {
|
||||||
peerAddress: req.peerAddress,
|
gh: req.gh,
|
||||||
discriminator: req.discriminator,
|
peerAddress: req.peerAddress,
|
||||||
slot: -1
|
discriminator: req.discriminator,
|
||||||
};
|
slot: -1
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return makeResponse(InitPlayerResult, {
|
return makeResponse(InitPlayerResult, {
|
||||||
code: 0
|
code: 0
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async GetRestrictions(source, data) {
|
async GetRestrictions(source, data) {
|
||||||
return makeResponse(GetRestrictionsResult, {
|
return makeResponse(GetRestrictionsResult, {
|
||||||
data: {
|
data: {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async ConfirmSessionEntered(source, data) {
|
async ConfirmSessionEntered(source, data) {
|
||||||
return {};
|
return {};
|
||||||
},
|
},
|
||||||
|
|
||||||
async TransitionToSession(source, data) {
|
async TransitionToSession(source, data) {
|
||||||
const req = TransitionToSession_Parameters.decode(data);
|
const req = TransitionToSession_Parameters.decode(data);
|
||||||
|
|
||||||
@@ -185,10 +192,12 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
|
|
||||||
async QueueForSession_Seamless(source, data) {
|
async QueueForSession_Seamless(source, data) {
|
||||||
const req = QueueForSession_Seamless_Parameters.decode(data);
|
const req = QueueForSession_Seamless_Parameters.decode(data);
|
||||||
|
|
||||||
playerDatas[source].req = req.requestId;
|
if (!isOneSync) {
|
||||||
playerDatas[source].id = req.requestId.requestor;
|
playerDatas[source].req = req.requestId;
|
||||||
playerDatas[source].slot = assignSlotId();
|
playerDatas[source].id = req.requestId.requestor;
|
||||||
|
playerDatas[source].slot = assignSlotId();
|
||||||
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
emitMsg(source, RpcMessage.encode({
|
emitMsg(source, RpcMessage.encode({
|
||||||
@@ -201,8 +210,10 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
optionFlags: req.optionFlags
|
optionFlags: req.optionFlags
|
||||||
}).finish()
|
}).finish()
|
||||||
}).finish());
|
}).finish());
|
||||||
|
|
||||||
if (hostIndex === -1) {
|
if (isOneSync) {
|
||||||
|
hostIndex = 16
|
||||||
|
} else if (hostIndex === -1) {
|
||||||
hostIndex = playerDatas[source].slot | 0;
|
hostIndex = playerDatas[source].slot | 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,11 +245,11 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
emitSessionCmds(source, 0, 'EnterSession', {
|
emitSessionCmds(source, 0, 'EnterSession', {
|
||||||
index: playerDatas[source].slot | 0,
|
index: (isOneSync) ? 16 : playerDatas[source].slot | 0,
|
||||||
hindex: hostIndex,
|
hindex: hostIndex,
|
||||||
sessionFlags: 0,
|
sessionFlags: 0,
|
||||||
mode: 0,
|
mode: 0,
|
||||||
size: Object.entries(playerDatas).filter(a => a[1].id).length,
|
size: (isOneSync) ? 0 : Object.entries(playerDatas).filter(a => a[1].id).length,
|
||||||
//size: 2,
|
//size: 2,
|
||||||
//size: Object.entries(playerDatas).length,
|
//size: Object.entries(playerDatas).length,
|
||||||
teamIndex: 0,
|
teamIndex: 0,
|
||||||
@@ -252,33 +263,35 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
slotCount: 32
|
slotCount: 32
|
||||||
});
|
});
|
||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
setTimeout(() => {
|
if (!isOneSync) {
|
||||||
// tell player about everyone, and everyone about player
|
setTimeout(() => {
|
||||||
const meData = playerDatas[source];
|
// tell player about everyone, and everyone about player
|
||||||
|
const meData = playerDatas[source];
|
||||||
const aboutMe = {
|
|
||||||
id: meData.id,
|
const aboutMe = {
|
||||||
gh: meData.gh,
|
id: meData.id,
|
||||||
addr: meData.peerAddress,
|
gh: meData.gh,
|
||||||
index: playerDatas[source].slot | 0
|
addr: meData.peerAddress,
|
||||||
};
|
index: playerDatas[source].slot | 0
|
||||||
|
};
|
||||||
for (const [ id, data ] of Object.entries(playerDatas)) {
|
|
||||||
if (id == source || !data.id) continue;
|
for (const [ id, data ] of Object.entries(playerDatas)) {
|
||||||
|
if (id == source || !data.id) continue;
|
||||||
emitAddPlayer(source, {
|
|
||||||
id: data.id,
|
emitAddPlayer(source, {
|
||||||
gh: data.gh,
|
id: data.id,
|
||||||
addr: data.peerAddress,
|
gh: data.gh,
|
||||||
index: data.slot | 0
|
addr: data.peerAddress,
|
||||||
});
|
index: data.slot | 0
|
||||||
|
});
|
||||||
emitAddPlayer(id, aboutMe);
|
|
||||||
}
|
emitAddPlayer(id, aboutMe);
|
||||||
}, 150);
|
}
|
||||||
|
}, 150);
|
||||||
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
|
|
||||||
return makeResponse(QueueForSessionResult, {
|
return makeResponse(QueueForSessionResult, {
|
||||||
code: 1
|
code: 1
|
||||||
});
|
});
|
||||||
@@ -292,20 +305,20 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
onNet('__cfx_internal:pbRlScSession', async (data) => {
|
onNet('__cfx_internal:pbRlScSession', async (data) => {
|
||||||
const s = source;
|
const s = source;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const message = RpcMessage.decode(new Uint8Array(data));
|
const message = RpcMessage.decode(new Uint8Array(data));
|
||||||
const response = await handleMessage(s, message.Header.MethodName, message.Content);
|
const response = await handleMessage(s, message.Header.MethodName, message.Content);
|
||||||
|
|
||||||
if (!response || !response.Header) {
|
if (!response || !response.Header) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.Header.RequestId = message.Header.RequestId;
|
response.Header.RequestId = message.Header.RequestId;
|
||||||
|
|
||||||
emitMsg(s, RpcResponseMessage.encode(response).finish());
|
emitMsg(s, RpcResponseMessage.encode(response).finish());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user