mirror of
https://github.com/citizenfx/cfx-server-data.git
synced 2025-12-12 06:14:09 +01:00
Merge pull request #184 from Disquse/redm-onesync-support
OneSync support for sessionmanager-rdr3
This commit is contained in:
@@ -15,6 +15,7 @@ function assignSlotId() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
@@ -89,6 +90,10 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
}
|
}
|
||||||
|
|
||||||
onNet('playerDropped', () => {
|
onNet('playerDropped', () => {
|
||||||
|
if (isOneSync) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const oData = playerDatas[source];
|
const oData = playerDatas[source];
|
||||||
delete playerDatas[source];
|
delete playerDatas[source];
|
||||||
@@ -151,12 +156,14 @@ 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
|
||||||
@@ -186,9 +193,11 @@ 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({
|
||||||
@@ -202,7 +211,9 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
}).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,
|
||||||
@@ -253,30 +264,32 @@ protobuf.load(GetResourcePath(GetCurrentResourceName()) + "/rline.proto", functi
|
|||||||
});
|
});
|
||||||
}, 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 = {
|
const aboutMe = {
|
||||||
id: meData.id,
|
id: meData.id,
|
||||||
gh: meData.gh,
|
gh: meData.gh,
|
||||||
addr: meData.peerAddress,
|
addr: meData.peerAddress,
|
||||||
index: playerDatas[source].slot | 0
|
index: playerDatas[source].slot | 0
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const [ id, data ] of Object.entries(playerDatas)) {
|
for (const [ id, data ] of Object.entries(playerDatas)) {
|
||||||
if (id == source || !data.id) continue;
|
if (id == source || !data.id) continue;
|
||||||
|
|
||||||
emitAddPlayer(source, {
|
emitAddPlayer(source, {
|
||||||
id: data.id,
|
id: data.id,
|
||||||
gh: data.gh,
|
gh: data.gh,
|
||||||
addr: data.peerAddress,
|
addr: data.peerAddress,
|
||||||
index: data.slot | 0
|
index: data.slot | 0
|
||||||
});
|
});
|
||||||
|
|
||||||
emitAddPlayer(id, aboutMe);
|
emitAddPlayer(id, aboutMe);
|
||||||
}
|
}
|
||||||
}, 150);
|
}, 150);
|
||||||
|
}
|
||||||
}, 250);
|
}, 250);
|
||||||
|
|
||||||
return makeResponse(QueueForSessionResult, {
|
return makeResponse(QueueForSessionResult, {
|
||||||
|
|||||||
Reference in New Issue
Block a user