From 00da6b5977574a0564169172227d8aab45be188f Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Sat, 3 Jan 2015 21:07:56 -0800 Subject: Switch MATCH to separate begin/end macros The for loop trick turned out to be very prone to infinite loops at runtime. It's better to force compiler errors even if it's ugly. --- src/map/map.cpp | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'src/map/map.cpp') diff --git a/src/map/map.cpp b/src/map/map.cpp index 784319f..e2c38a7 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -1247,36 +1247,40 @@ void map_setcell(Borrowed m, int x, int y, MapCell t) int map_setipport(MapName name, IP4Address ip, int port) { Option> md_ = maps_db.get(name); - if OPTION_IS_SOME_NOLOOP(md, md_) + OMATCH_BEGIN (md_) { - if (md->gat) + OMATCH_CASE_SOME (md) { - // local -> check data - if (ip != clif_getip() || port != clif_getport()) + if (md->gat) { - PRINTF("from char server : %s -> %s:%d\n"_fmt, - name, ip, port); - return 1; + // local -> check data + if (ip != clif_getip() || port != clif_getport()) + { + PRINTF("from char server : %s -> %s:%d\n"_fmt, + name, ip, port); + return 1; + } + } + else + { + // update + P mdos = md.downcast_to(); + mdos->ip = ip; + mdos->port = port; } } - else + OMATCH_CASE_NONE () { - // update - P mdos = md.downcast_to(); + // not exist -> add new data + auto mdos = make_unique(); + mdos->name_ = name; + mdos->gat = nullptr; mdos->ip = ip; mdos->port = port; + maps_db.put(mdos->name_, std::move(mdos)); } } - else - { - // not exist -> add new data - auto mdos = make_unique(); - mdos->name_ = name; - mdos->gat = nullptr; - mdos->ip = ip; - mdos->port = port; - maps_db.put(mdos->name_, std::move(mdos)); - } + OMATCH_END (); return 0; } -- cgit v1.2.3-60-g2f50