Guild icon
DDraceNetwork
Development / developer
Development discussion. Logged to https://ddnet.tw/irclogs/ Connected with DDNet's IRC channel, Matrix room and GitHub repositories — IRC: #ddnet on Quakenet | Matrix: #ddnet-developer:matrix.org GitHub: https://github.com/ddnet
Between 2021-07-15 00:00:00Z and 2021-07-16 00:00:00Z
Avatar
cedaaec A Mountain Silence, M DarkCore 3, M Dead Darkness - ddnet-maps
07:34
- The paste IDs we hand out start as 2-letter permutations of [A-Za-z0-0]
0-0?
Avatar
chillerdragon BOT 2021-07-15 07:53:09Z
@TsFreddie: ?
07:53
oh 0-0
07:53
ye go fix
07:54
its a typo of 0-9 as you can see in this sample paste including a 9 https://paste.zillyhuhn.com/69
07:54
hihih 69
Avatar
chillerdragon BOT 2021-07-15 07:58:21Z
when make pr @TsFreddie ?
Avatar
how about never
Avatar
chillerdragon BOT 2021-07-15 07:59:22Z
ass
07:59
thenn ill do it
Avatar
ye. glory awaits
08:04
you did it 💯, proud of you
Avatar
chillerdragon BOT 2021-07-15 08:04:31Z
ofc
Avatar
@Learath2 what rust sv r u in?
09:17
i couldnt find u on the official one
09:17
pepeH
Avatar
7. If you come here for the game Rust, you will be kicked without warning.
Avatar
add that to ddnet rules
Avatar
7. If you come here for the game Teeworlds, you will be kicked without warning.
11:30
monkalaugh
Avatar
This would make some startline skips harder to exploit.

Checklist

  • [x] Tested the change ingame
  • [ ] Provided screenshots if it is a visual change
  • [ ] Tested in combination with possibly related configuration options
  • [ ] Written a unit test if it works standalone, system.c especially
  • [x] Considered possible null pointers and out of bounds array indexing
  • [ ] Changed no physics that affect existing maps
  • [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](ht...
Avatar
@heinrich5991 hm, could moving the tee a bit be acceptable?
Avatar
I guess the idea is that being blocked from changing the team due to this is annoying
12:01
I agree with that
12:02
I can't immediately see problems with it, but it sounds icky, and it sounds like something that might be exploited on its own
12:02
I could reduce the range where it blocks you from joining a team, e.g. only block exactly stacking tees
Avatar
Avatar
Learath2
@heinrich5991 hm, could moving the tee a bit be acceptable?
I solved this by adding 0.2f to the y vel
12:13
minus*
Avatar
Adding to velocity sounds dangerous somehow, but nudging the position should be relatively safe?
Avatar
the trait Encode<'_, Sqlite> is not implemented for u64
If only sqlx was half as mature as it pretended to be 😛
15:27
Guess I'll just store everything as strings instead
Avatar
@Learath2 i think sqlite doesnt have unsigned
15:31
15:31
i guess thats why they dont impl it
15:31
😛
15:32
15:32
see
15:32
its deliberate
15:32
15:32
hmm
15:32
xd
15:32
idk
Avatar
hm, sqlite3 C interface clearly allows you to get 64b values and store them
15:33
sqlite3_value_int64
Avatar
thats not uin64 tho
15:33
uint64*
15:34
15:34
sqlite doesnt have unsigned values at all
Avatar
Hm, you can store an 64 bit unsigned in a 64 bit signed. Sqlite doesn't even support different types at all internally
Avatar
everything is a i64
Avatar
The only value types in sqlite internally is 64b signed integer, 64b ieee float, string, blob and null iirc
15:35
Anyway, they can indeed implement a u64 one, I think it's just an oversight
Avatar
i guess
15:35
open a pr
15:35
or issue
15:36
the good thing of open source
15:36
monkalaugh
Avatar
I will give it a go after I finish up this mess
Avatar
It seems that sqlx currently has no support for unsigned 64bit integer values (u64). Especially for contents like file sizes, timestamps etc. this would be very favourable as SQLite has native supp...
15:38
@Learath2 isnt it a bit pointless to do everything async and paralel to end up using sqlite, which is not paralel at all from my understanding
15:38
concurrent*
Avatar
The plan wasn't to use sqlite, that's another limitation of sqlx that sort kicked me in the gut 😛
15:39
sqlx supports psql and mysql too
Avatar
The plan was to use the Any backend and I was going to use sqlite to test locally so I don't have to set up database servers
15:40
However, the Any backend has very very weird interaction with the query! macro, as in it doesn't respect the DATABASE_URI at all
15:41
So I ended up scrapping any hope of keeping this generic and just finished it up in the interest of getting the immediate need for a working bot satisfied
15:42
The new version I'm planning will probably use diesel, which works a little better in the genericity department but suffers from having very meh async support
Avatar
very meh as in it doesnt have
Avatar
there are 3rd party crates to help with it atleast
Avatar
bringing orm-like features to sqlx. Contribute to NyxCode/ormx development by creating an account on GitHub.
15:44
doesnt seem very maintained but it is there
15:44
xd
15:44
i personally use sqlx and generate stuff with this https://github.com/edg-l/modelizer
Contribute to edg-l/modelizer development by creating an account on GitHub.
15:44
it is very tailored to my needs tho
Avatar
I might also say fuckit and just do all of the concurrency by hand
Avatar
why not, in rust u can do it without fear
15:45
greenthing
15:45
u just have to take care of possible deadlocks
Avatar
Anyway, I need to finish this first, after we have a working bot I can work on making a clean bot
Avatar
async is for bitches
15:46
poggers
Avatar
I'm actually on the fence with async aswell, I'm sure it utilizes the cpu better than I could by hand but it is completely missing some of the context we as programmers have
15:47
I wonder how a task just hopping across workers affects performance, how it plays with cache locality etc..
15:48
for me async backends are a black box
Avatar
You should read up on how rust does async, it's actually fairly interesting how the runtimes manage their tasks
Avatar
i should
Avatar
hi, why after that when such information as the IP address, the list of servers, etc. disappears? It is updated anew as if it has been cleaned
Avatar
wut is strstr
15:52
so long since i dont touch ddnet code
15:52
Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.
Avatar
@Ryozuki Q: When you want to store a type without an encode/decode implementation in sqlx, what do you do? Do you implement it for yourself or do you convert to a type it understands?
Avatar
@Learath2 i never found myself in that situation, is this for a type made by a crate u dont control?
Avatar
Avatar
σℓí♡
hi, why after that when such information as the IP address, the list of servers, etc. disappears? It is updated anew as if it has been cleaned
I'm not quite sure how your code relates to your question, I don't really get the question either, can you try to rephrase?
Avatar
Avatar
Ryozuki
@Learath2 i never found myself in that situation, is this for a type made by a crate u dont control?
One type I created, one for a crate I don't control
Avatar
can u show me the type u made
15:54
usually types are made of other types and those simpler types impl the encode decode right? so u should just derive fromrow or smth?
Avatar
It's an enum of two types from a crate I don't control
Avatar
I commented on this part when, and there were no problems, but if I use this, then everything works, but there is a problem. I go to the menu and there is no selected server and all the information is loaded again
Avatar
The types from the crate I don't control cleanly map to u64 and I don't mind discarding the type information on the enum while storing, I can derive it again when loading
Avatar
Avatar
σℓí♡
I commented on this part when, and there were no problems, but if I use this, then everything works, but there is a problem. I go to the menu and there is no selected server and all the information is loaded again
Avatar
i guess i would impl Decode but maybe its not worth
15:57
then u would have to do select x as "x: MyType" (or _) if u use the macros iirc (edited)
Avatar
Avatar
σℓí♡
Click to see attachment 🖼️
Mh, it doesn't really happen for me. If I join a server and check the ingame browser the selected server is still there
15:59
Did you change something in the code that could break this?
Avatar
Avatar
σℓí♡
hi, why after that when such information as the IP address, the list of servers, etc. disappears? It is updated anew as if it has been cleaned
I provided a screenshot of the code above, which is why this problem occurs, I change my color or the like, after which this happens
16:01
maybe because I change it directly g_Config.m_ClPlayerColorBody
16:02
omg
16:03
i love whoever made this
16:03
and they use rust
16:03
im a doctor who fan
16:03
Avatar
their ascii thing is messed up
Avatar
Avatar
σℓí♡
hi, why after that when such information as the IP address, the list of servers, etc. disappears? It is updated anew as if it has been cleaned
Ah I know what you broke
Avatar
no its not
Avatar
64 is way too much, playerskin is only 24 characters. Instead of 64 use sizeof(g_Config.m_ClPlayerSkin)
Avatar
its some kind of wave
Avatar
@σℓí♡ what are you making btw?
16:06
monkalaugh
16:06
idk why anyone not purple asking for code is always a botter
Avatar
hopefully not, it'd be very sad if I helped a botter 😛
Avatar
its always ppl who are never active in this discord
16:06
probs using 2nd account maybe
Avatar
skin stealer it's bot?
Avatar
Looks like a remote controlled tee with the ability to change colors on messages, didn't look very dangerous to me 😛
16:07
u will look fishy to anyone if u use it
16:07
and they will probs call a mod and ban u
16:08
cuz u will be fishy
Avatar
Eeeeeh, not really that problematic by itself but mods will be suspicious yes
Avatar
actual bot clients already have that feature
Avatar
might async be overkill for a discord bot?
Avatar
i guess it depends on the scale
16:09
if its used for this sv i guess its overkill
Avatar
maybe this is a more general question
Avatar
but maybe the discord library is not async but implements sharding
Avatar
when does async outperform spawning a couple of threads
Avatar
Yeah very tough question too, depends a lot on the runtime and how good it is
Avatar
i think async threads are way cheaper
16:10
than os threads
16:10
tokio claims this
Avatar
Avatar
Learath2
64 is way too much, playerskin is only 24 characters. Instead of 64 use sizeof(g_Config.m_ClPlayerSkin)
big ty
Avatar
@Ryozuki got a link?
Avatar
Tasks are light weight. Because tasks are scheduled by the Tokio runtime rather than the operating system, creating new tasks or switching between tasks does not require a context switch and has fairly low overhead. Creating, running, and destroying large numbers of tasks is quite cheap, especially compared to OS threads.
Avatar
hm, doesn't have numbers
16:11
I'd imagine it varies wildly by OS
Avatar
I guess it's fair to say async can saturate a cpu easier than threads, since with enough tasks it can ensure every thread is working
16:14
Not really quite sure tbf, but async code is a good abstraction over the rather complicated issue of threading an application. Atleast in the sense that it makes it easier for a programmer to be efficiently using resources without having to think too much about it
Avatar
I see
16:14
so the "only" downside is rust's immature async support?
Avatar
thats how i feel about it too
Avatar
Avatar
heinrich5991
so the "only" downside is rust's immature async support?
Well I think so, I'm sure there are people far more qualified than me to comment on this.
Avatar
Avatar
Learath2
I'm actually on the fence with async aswell, I'm sure it utilizes the cpu better than I could by hand but it is completely missing some of the context we as programmers have
As I said ^^. I'm not quite sure if the runtimes are good enough at moving tasks around and inferring relationships between them.
Avatar
ah, apparently async is also a memory usage optimization
Avatar
I have a feeling I'm still holding a lot of rust wrong, but it is fun to learn more
Avatar
nice 🙂
Avatar
e.g. this https://paste.pr0.tips/hH just doesn't look quite right 😄
Avatar
I still find it weird that you use a RwLock<()> ^^
Avatar
maybe it's the library interface just not being flexible enough, maybe it's me not really holding it correctly
Avatar
Avatar
heinrich5991
I still find it weird that you use a RwLock<()> ^^
Well if you have a minute we can try to discuss it, I really don't see how else to make this safe
Avatar
I think we discussed it before, but I'm interested in why we didn't come up with a better solution
16:34
ah, was it that sqlx doesn't support transactions?
Avatar
Well let me give you a concrete example I couldn't reason about and thus think I have to lock the entire table somehow
16:37
Tester A approves map M, Tester B approves map M at the same time. Task T_A launches and gets the row corresponding to the submission from the db. Before Task T_A gets to mark it as evaluated, Task T_B also gets the row. Now we have two threads trying to approve the same map
Avatar
can you start transactions?
Avatar
I can, but I'm not completely sure what kind of guarantees that gives me. Afaik sqlite doesn't even have the kind of transaction I require
Avatar
if I read the docs correctly, you can start a IMMEDIATE transaction, and that gives you exclusive write access
Avatar
sqlx doesn't even expose this to me
16:41
So I settled for a rwlock that isn't really attached to any type and used the usual "advisory lock" pattern
Avatar
but you can start a transaction, apparently
Avatar
I can but I don't see any api for what type of transaction gets started
Avatar
I don't know which of these transactions it is, but all three are okay for you
Avatar
When I begin a transaction doesn't that lock the entire db though? If say I do an immediate one
Avatar
it locks the DB for writing
16:42
not reading
16:43
reads will use the state of the DB before your transaction
Avatar
And if someone wants to write?
Avatar
what I'm more worried about is how to detect that you can write again
16:43
that will be blocked until your transaction finishes
Avatar
The tables here are also independent, locking the entire db is sort of unnecessary, but I could do that for cleaner codes sake
Avatar
I see
16:44
what does your sqlite library do with SQLITE_BUSY errors?
Avatar
let me take a look
16:46
Ok so first of all https://github.com/launchbadge/sqlx/issues/481 means I'm right about sqlx not exposing the different kinds of transactions yet
There are four transaction isolation levels in SQL language and most of database support them. But I can't find how to set isolation level for transactions in sqlx. Is it a missing feature?
16:47
I'll take a look at the source to see what they are doing with the SQLITE_BUSY
Avatar
I also took a look
16:54
apparently waiting, and then returning SQLITE_BUSY to the user after (by default) 5 seconds
Avatar
Hm, where did you get that? I was just about to conclude that it just returns an error like any other error from the db
16:58
I think the 5s might be on the sqlite side?
Avatar
I grepped for busy (case-insensitive)
16:58
it asks sqlite3 to do the waiting
16:58
but it sets its own default value (5s)
16:58
grep for sqlite3_busy_timeout
Avatar
ah, found it
17:00
Hm, that is quite annoying to leave to the poor user to handle, it's also something I can't wait on effectively
Avatar
I guess you handle it like other errors?
17:01
what are you gonna do, wait longer? ^^
Avatar
If I could start an immediate transaction I could busy loop until I get to start one, but there is no guarantee for me to get one, by sheer luck one task could starve forever
17:02
I actually wouldn't mind a task sleeping until the database isn't busy, if there was any wake up guarantee
17:04
Yeah I can't really drop these locks atleast until they expose immediate transactions
17:05
When they have immediate transactions I can get the row, immediately modify it to show the new state and commit so I don't lock too long, and T_B never ends up getting the exact same row as T_A
17:06
This does sound very wrong though, immediate transactions are a sqlite thing. How do people ensure this kind of thing doesn't happen in mysql and psql?
Avatar
you have other things that write to the db, no?
17:06
then you can probably still get SQLITE_BUSY errors
17:06
also transactions, probably? why do you need an IMMEDIATE transaction, specifically?
Avatar
A non immediate transaction means I can get a busy within the transaction
17:07
Busy within the transaction means I need wrappers for all my queries that busy loop until they can get their change in
17:08
With immediate transactions I can busy loop just once to get my exclusive access
Avatar
I see
Avatar
idk maybe there is a way turn this into a non-racy pattern, but I'm not seeing it
17:09
I basically need an atomic read-modify-write but in sql
Avatar
does rwlock guarantee that you don't starve btw? probably not, how would it
17:09
but the transcation provides this(?)
17:10
you might just need to retry
Avatar
tokio rwlocks ensure writers are not starved
Avatar
ah nice
Avatar
and they are fair due to using a fifo queue
Avatar
Avatar
heinrich5991
you might just need to retry
is this really acceptable? I'd basically need busy waiting, with no guarantee that I'd ever get through
Avatar
This is in contrast to the Rust standard library’s std::sync::RwLock, where the priority policy is dependent on the operating system’s implementation.
17:13
I guess there should be some kind of "wait for transaction" sqlite3 command
17:14
SQLite is not terribly helpful when it comes to concurrency. By default, it does not even provide any fairness guarantees (although you can write them yourself as long as your concurrency is happening within the same process).
Avatar
I guess my rwlock qualifies as "write them yourself". An outside process is a bit of an issue but I currently don't have any
Avatar
you'd need a write lock for the whole db though, not just this table(?)
Avatar
Hm, I guess it is actually possible that a two threads smack in the middle of a query collide and since sqlite doesn't allow concurrent writes even to discrete tables this would break
17:17
okay I guess my attempt at this isn't exactly safe either
17:18
eh, this is just a field I'm not well versed enough to do this properly
Avatar
concurrency is hard who would have said
Avatar
The documentation I read about this really exposes a very uncomfortable interface. With essentially each and every query having to be wrapped in a while(rc == SQLITE_BUSY) and that sounds absolutely insane to me
Avatar
hm
17:23
I'd think it's the transactions that need to be wrapped in that
17:23
not individual queries
17:23
but still annoying
Avatar
for an immediate transaction that is true, but for other ones I'm not so sure
Avatar
there are cases where you need to redo your entire (also non-immediate) transaction
17:25
e.g. if another connection did writes to the DB since you read
Avatar
um, how is that signalled?
Avatar
apparently with SQLITE_BUSY_SNAPSHOT if extended error codes are enabled
17:27
otherwise SQLITE_BUSY
17:28
Avatar
This one actually sounds useful, in my usecase
17:30
One thing this entire adventure revealed is that database systems are much more strict than I initially thought
Avatar
can you elaborate what you mean by "strict"?
Avatar
Well in the case of sqlite it supports concurrency in a very specific way. Whether tables depend on eachother or not writing is only allowed for one connection at a time. Whether your transaction cares about other writes during it or not you are getting a SQLITE_BUSY_SNAPSHOT
Avatar
I see, so strict in the meaning of "not supporting many options, e.g. many concurrency models"
Avatar
Yes, I guess that's what I had in mind
Avatar
@ScReeNy what do you mean by "unlock finishing"? (edited)
17:34
that you join team 0 after finishing in team?
Avatar
yes if you finish in an unlocked team you join team 0 and can stack
Avatar
and this can be abused?
Avatar
by this you can stack tees in one tile and do a stack hammer
17:38
idk if this actually gets used, i only did once but it got fixed
17:38
doesnt work on many maps
Avatar
ok, so that might need fixing, too
17:39
how about allowing people to join team 0 while standing on the finish tile?
17:39
and automatically letting them join team 0 if there's space during finish
17:40
hm, not much different than always allowing them to join team0 after finishing
17:40
after all, the last tee might just wait for everyone to get into position before finishing
Avatar
InnoDB locking in mysql seems much more flexible allowing table and even row level locks
Avatar
Avatar
heinrich5991
after all, the last tee might just wait for everyone to get into position before finishing
yes thats how you do it
Avatar
Avatar
Learath2
InnoDB locking in mysql seems much more flexible allowing table and even row level locks
well sqlite is supposed to be rly simple
Avatar
so only joining people to t0 that are currently unblocked and allowing the rest to join t0 whenever they want would work @ScReeNy?
Avatar
Avatar
Ryozuki
well sqlite is supposed to be rly simple
it is indeed, maybe picking one concurrency scheme and sticking to it does make it cleaner. afterall all the memory ordering stuff in atomics doesn't make it very easy to reason about them
Avatar
Avatar
heinrich5991
so only joining people to t0 that are currently unblocked and allowing the rest to join t0 whenever they want would work @ScReeNy?
if you count in unlock finish yes. This wont fix everything but at least shouldnt cause issues.
Avatar
thanks. I'll post this to the issue if that's okay 🙂
Avatar
what do you call an identifier that lets you unambiguously identify which of two objects is newer, like a timestamp, but might be arbitrary data
17:52
version?
17:52
@Learath2? 🙂
Avatar
serial is also common
Avatar
interesting, haven't heard that before
Avatar
well common is reaching, but I've seen it 😄
Avatar
I'm trying to find a name for the "serial" of the info object sent by the game server to the master server
17:54
so that old lingering requests do not cause the masterserver to distribute outdated server info
Avatar
Ah I think serial is perfect for that, it even implies the number will be increasing
Avatar
"info_serial"?
Avatar
the first time I heard serial was in context of dns zones btw, bind9
Avatar
ah nice
Avatar
Avatar
heinrich5991
"info_serial"?
sounds good to me
Avatar
if it's used by bind9, it's probably the right term ^^
Avatar
maybe the info_ is redundant? it's already part of the info after all, no?
17:58
hm, actually it is more metadata about the info than part of it
Avatar
I put it next to the info
17:58
since the masterserver needs to interpret it
Avatar
yeah, makes sense
17:59
oh, btw could you get a chance to look at the filtering issue @fokkonaut was having?
Avatar
its basically fine again
Avatar
ah true, should do that
Avatar
it fixed itself?
Avatar
i just need 128p support (for client info/clan/etc)
Avatar
Avatar
Learath2
it fixed itself?
Yes, i said that from the beginning. if i send as much client infos as there are clients online, then it works
Avatar
Oh, that's not fixing itself, you fixed it
Avatar
afk food. will read afterwards
Avatar
Avatar
fokkonaut
I fixed it by sending empty strings and 0's as playerinfo to fill the rest up
.
Avatar
@heinrich5991 the master server doesn't really care how many players the server says it has now. Maybe it should? I think it's sane to allow incomplete ones, with maybe some ui indication that not all the info was sent
Avatar
that sounds good
18:01
i guess
Avatar
the masterserver does indeed not care about the number of players
18:02
it's just that the json (intentionally) has no player count field
Avatar
no num_players and no num_clients
Avatar
because that'd duplicate info from the players array
Avatar
did you ever think about sv_server_info_per_second?
Avatar
yes, I consider the current setup the backwards compatibility
Avatar
But it's technically not duplicate info if we allow less playerinfo to be sent
Avatar
Avatar
heinrich5991
yes, I consider the current setup the backwards compatibility
sorry, but obviously not
Avatar
that was just a hack (sv_server_info_per_second)
18:03
but it fucks the info right now
18:03
client sorts it out
Avatar
it'll get better 😉 I'm even working on it
Avatar
i dont doubt
Avatar
what are you doing? the server -> masterserver part?
Avatar
yes
Avatar
how do i open a file with fopen? absolute or relative path?
18:04
i cant seem to open it
Avatar
either is fine
Avatar
doesnt work lul
18:04
returns 0
18:04
ah no
18:04
im dumb
18:04
wrong var
18:05
lol how can i see stuff like this only when i ask here
18:05
xD
Avatar
it's the same thing that happens when you call a professional to take a look at something
Avatar
yea, immediately its clear
18:05
or pops to your eye
Avatar
I had intermittent issues with electricity that never happened when the electrician is here
Avatar
I've decided the sanest way to do concurrency in sqlite is to treat SQLITE_BUSY as fatal, let the user retry
18:08
With the delays introduced by the human element the conflicts should be rare enough that handling them just makes the code dirty
Avatar
https://beets.io/blog/sqlite-nightmare.html seems I wasn't the only one to resort to locking at language level for sqlite
Avatar
Oh I'm an absolute goof, my locking doesn't even work at all 😄
18:59
Need to hold the lock longer, I guess I'll do a whole database lock and abstract over transactions
Avatar
at that point you could put the db into the rwlock \o/
Avatar
I could indeed, even better would be to have 2 connections, one for writing and a pool for reading and a rwlock coordinating so I never have to deal with SQLITE_BUSY at all
Avatar
what do the cool kids use for multithreading in ddnet these days? i remember using thread_init and also the pain i experienced with it? i want to issue some requests asynchonously and if possible also get the result 😄
Avatar
(still painful though)
Avatar
depends on your definition of pain a lot 😄
19:08
I mean it's not as trivial as futures maybe, but it's not much more painful than threading in just C/C++
Avatar
thanks, i will read into it 🙂
Avatar
PostgreSQL has built-in JSON generators that can be used to create structured JSON output right in the database, upping performance and radically simplifying web tiers.
20:42
:o
Avatar
Anyone does know java well? (edited)
Avatar
ask your question
20:52
this website fits so perfectly
20:52
and its always java
20:52
20:52
monkalaugh
Avatar
Yea but
Avatar
no yeas
Avatar
Bit operations
20:54
I have 12 tasks
20:54
And 4 of them made my brain...
Avatar
idk the others but im not here to do ur homework xd
Avatar
Just wanna ask for some advices
Avatar
then ask
Avatar
How can i make binary number higher bit to 0, with simple bit operations?
20:56
Only simple (edited)
Avatar
| 0x80000000
Avatar
see, that doesnt even require java
Avatar
Anyway
Avatar
do you want to set the highest bit to 1?
Avatar
I need to set the highest 1 to 0
20:57
With any number i scan
Avatar
ah
20:57
you want to set the highest bit that is 1 to 0
20:59
?
Avatar
Yes, how to set the lower i know, how to set the 2nd, 3rd etc ik too, but if number changes its higher 1 from one rank to another
Avatar
sorry, I don't understand what you say
21:00
can you give an example?
Avatar
Ehm
21:00
So
21:00
I mean, i need a code which inverts higher 1 to 0
21:00
For example
21:01
11000 i need to get 01000, and if number will be 10110000, so i need to convert a higher 1 as well, to 00110000
Avatar
I see
21:02
so we can split up the problem into "find the index of the highest 1" and "set that 1 to 0"
Avatar
Yea
21:02
But
21:02
Only with simple bit operations
Avatar
how can you test whether the n-th bit is set?
21:02
say you have the number x
21:03
can you write java code that checks if the n-th bit is set?
Avatar
If i know n i can use >>n
21:03
And using if, its 1 or 0
Avatar
this expression doesn't contain x, it can't be the solution
21:04
static void checkNthBit(int x, int n) { [...] }
21:04
fill the function so it outputs "1" if the n-th bit of x is set and "0" otherwise
Avatar
@Ryozuki I wanted it on stdout
Avatar
With void check yea, but what about using only ~, |, & or ^ and << >>
Avatar
Avatar
Ryozuki
void monkaS
#define void int
Avatar
use those
21:06
he asking u to do it
21:06
heinrich the good teacher
Avatar
But i hadnt used english for a while, so im a bad explainer :(
Avatar
whats ur main language
Avatar
Rus
21:07
sorry
Avatar
java xd
21:07
we dont have any rus dev that i know here
21:08
monkaS
Avatar
Sad af
21:08
banzai is ukraine
21:09
BannZay*
Avatar
how am I going to do the port forward check in the https masters?
21:27
I want to send a challenge that the game server has to include in its next register attempt
Avatar
faceless можешь мне рассказать, я переведу
21:46
@Deleted User
Avatar
Да уже вроде вспомнил как на англ разговариватт
Avatar
ping me if u need help
Avatar
Avatar
heinrich5991
how am I going to do the port forward check in the https masters?
Hm, can we use the old protocol? or do you need something new?
Avatar
need something new, the old protocol doesn't have challenge-response
Avatar
@heinrich5991 okay, hm, this is a tad annoying to add but maybe just a large-ish packet similar to the 0.7 CONNECT?
Avatar
probably add some bytes that can be set by the game server so that the game server can see that it comes from a legitimate masterserver?
Avatar
why do you wnat to make it large? @Learath2
Avatar
I wanted to discourage people from spamming it
Avatar
it can include "authentication" in the form of bytes only known to the game server and the masterserver
Avatar
and it'd lead to a worse than 1 reflection ratio
Avatar
it wouldn't reflect at all if it doesn't include the "authentication"
Avatar
@heinrich5991 it should definitely include authentication, my initial implementation included a secret sent with the info to make sure
22:27
You know what would be cute in rust? C++14s operator""s
Avatar
can you convince me of that? ^^
Avatar
String::from("Test string") vs "Test string".to_owned() vs "Test string".to_str() vs "Test string"s
22:29
One is much much easier to type than the others 😄
22:30
Especially when you need a lot of them to initialize say a default value for a struct with many Strings in it
Avatar
hm, not really convinced
22:32
sounds like bloat
22:32
can you do .into()?
Avatar
I mean it's not getting shorter than ""s, into does work but it still looks meh imo
22:36
Why do you think it is bloat? When there is a prettier way to do things it usually gets in. E.g. the unstable try blocks
22:36
You can get their behaviour using a closure
Avatar
try blocks are unstable since forever
22:38
also, there's something you can't do from a closure, returning from the outer function
Avatar
btw rust already has literals, I don't really see why extending them to some heap types hurts
Avatar
hm. dedicated syntax for .to_owned() for just strings is a bit underwhelming for a new language feature
22:39
also, rust tries to make less efficient stuff more verbose, String is less efficient than &'static str
22:40
(I realize you could theoretically use operator"" for other stuff, but I don't know any)
Avatar
Avatar
heinrich5991
hm. dedicated syntax for .to_owned() for just strings is a bit underwhelming for a new language feature
C++ thought so too, so they introduced user defined literals along with it. Maybe in that form it's more palatable to you
Avatar
also it kinda does away with namespacing
Avatar
I'm out of arguments, it looks pretty to me so that's enough for me 😄
Avatar
ok, about the masterserver forward check
22:45
it doesn't really have to be large if it includes some bytes chosen by the game server, right?
Avatar
how do I best format the challenge/response in JSON?
22:54
should it be a zero-terminated string in the packet and a normal JSON string?
22:54
or a byte array in the packet and a array of numbers < 256 in JSON?
Avatar
byte array in the packet and a base 64 encoded string in the json maybe?
22:56
If you don't want to bother encoding your first suggestion would be what I do
Avatar
what about a hex string vs base64? ^^
22:57
hex is already implemented in teeworlds ^^
Avatar
Sure that works too, b64 is just shorter is why I had it in mind
Avatar
I mean, time to write a b64 encoder/decoder I guess 😄
Avatar
a byte saved here and there doesn't really matter anyway for this, we don't do fwchecks all the time
Avatar
actually, we do (at least currently)
22:57
ah, but I'll drop it, since the game server can continue to provide the proof
Avatar
hm, do we? I thought we only did simple heartbeats after the first fwcheck stuff
Avatar
Avatar
heinrich5991
ah, but I'll drop it, since the game server can continue to provide the proof
how will the gameserver prove it is connectable if not continuous fwchecks actually?
Avatar
I'm assuming it won't go away immediately
22:59
by replaying the secret I sent in the port forward challenge from the masterserver
Avatar
So wait the protocol is the server sends info with secret, master sends secret + challenge, the server sends response to some other endpoint on the master?
Avatar
the server sends info with secret + challenge @Learath2
23:16
(at the end)
Avatar
Ah, okay. But you still need to keep challenges to make sure the server is still alive, no?
23:17
keep sending*
Avatar
hm, every few minutes might be enough, no?
Avatar
Yep, sounds good
Avatar
the server sends its heartbeats more often
23:19
(I think the port forward check isn't relevant to security, it just helps people figure out that their servers are unreachable. in the end, the game server could just respond to port forward checks and nothing else, and it would be the same result for the user as elaborate "port forward faking")
Avatar
Yeah, sounds sane to me
23:28
https://paste.pr0.tips/P2 does this not look very cute? 😄
Avatar
looks good
23:29
maybe only retry on BUSY?
Avatar
I was considering that but there are 3 issues with that: 1) I want to retry on LOCKED too, 2) sqlx doesn't really expose it in a way I can match easily, maybe I can hard code a numeric code there, 3) it wouldn't be cute 😄
Avatar
^^
Avatar
Maybe when I'm making a cleaner version I'll directly use the database library instead of an abstraction
Avatar
hi, i added a field to the NETSOCK struct, and for some reason it gets mem_zero'd some times... any ideas why? cant find any explicit mem_zero calls
Avatar
no idea
23:48
you could try setting a memory breakpoint in gdb
Avatar
i was trying to dodge that, but it seems like i have no choice 😄 thanks
Avatar
doesn't seem too bad to me?
Avatar
never done that with gcc...
23:50
learning something new every day 🙂
Avatar
watch <address>, I think
Avatar
it's actually extremely simple and a very useful tool to learn to use
Avatar
how do i get hold of the address though?
Avatar
break somewhere where you have access to it
23:51
probably in CNetClient initialization or so
Avatar
You can do &sock.mynewfield gdb will figure out the address of the field for you
Avatar
(if sock is in scope)
Avatar
what was the cmake debug flag again?
23:53
sorry xd
Avatar
-DDEV=ON
23:54
(for teeworlds/ddnet. in general it's -DCMAKE_BUILD_TYPE=Debug, I think)
Avatar
-DCMAKE_BUILD_TYPE=Debug is what I use, what does -DDEV=ON do?
Avatar
it's ddnet specific. saner defaults for developing IIRC
23:55
the default configuration is for packaging
Avatar
@heinrich5991 I have another request for rust, compound literals
Avatar
is that "abc" "def"?
Avatar
No C99 ones (struct foo){"foo", 3}
Avatar
hm, rust has these, no?
23:59
you need to name the fields though
Avatar
consider using a let binding to create a longer lived value
This is the issue I'd like to work around
Exported 522 message(s)